Socket programming is a way of connecting two nodes on a network to communicate with each other. One socket(node) listens on a particular port at an IP, while the other socket reaches out to the other to form a connection. The server forms the listener socket while the client reaches out to the server.
Socket programming is started by importing the socket library and making a simple socket.
import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Here we made a socket instance and passed it two parameters. The first parameter is AF_INET and the second one is SOCK_STREAM. AF_INET refers to the address family ipv4. The SOCK_STREAM means connection-oriented TCP protocol.
Note: For more information, refer to Socket Programming in Python
Now we can connect to a server using Server:
A Server is a program that provides service to other computers on the network or Internet. Similarly, a client is a program that receives services from the server. When a server wants to communicate with a client, there is a need for a socket. A socket is a point of connection between the server and the client.
TCP/IP server program that sends message to the client.
TCP/IP server program that receive message from server.
Note: Open In Two Separate DOS Windows And First Execute server, then Execute client.
Output of Server:
Output of Client:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Hadoop - Python Snakebite CLI Client, Its Usage and Command References
- Convert Text to Speech in Python using win32com.client
- Python | Prompt for Password at Runtime and Termination with Error Message
- Python PyQt5 – How to change font and size of Status Bar Message
- How To Encode And Decode A Message using Python?
- Python | Message Encode-Decode using Tkinter
- Python | Issue Warning Message
- Create a Yes/No Message Box in Python using tkinter
- Python Tkinter - Message
- Send message to Telegram user using Python
- Python EasyGUI - Message Box
- Send Direct Message On Instagram using Selenium in Python
- hmac - Keyed-Hashing for Message Authentication
- PyQt5 – Set status bar message in window
- Message Boxes using PyAutoGUI
- Hello World Program : First program while learning Programming
- Python program to check if the list contains three consecutive common numbers in Python
- Python program to split and join a string
- Python program to interchange first and last elements in a list
- Python program to count upper and lower case characters without using inbuilt functions
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.