Socket Programming and have fun with Python
Client Socket and Server Socket:
Client Computer like your browser or any piece of code you want to talk to your server uses client socket and Server uses both client and server socket.
Sockets are great for Cross-Platform communication.
Following is minimal Example of Socket and stuff:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("www.python.org", 80))
What is INET?What is Sock_Stream?
Almost that is all happened on client side, When connect is completed socket that is ‘s’ we just created can be used to send and request the specific text page requested. This socket will be read and reply, after that it will be destroyed. Client sockets are normally only used for one exchange (or a small set of sequential exchanges).
Now let’s look what is happening at server side:
# create an INET, STREAMing socket serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # bind the socket to a public host, and a well-known port serversocket.bind((socket.gethostname(), 80)) # become a server socket serversocket.listen(5)