Socket Programming
Socket Programming
SERVER:
A server has a bind() method which binds it to a specific IP and port so that it
can listen to incoming requests on that IP and port. A server has a listen()
method which puts the server into listening mode. This allows the server to
listen to incoming connections. And last a server has an accept() and close()
method. The accept method initiates a connection with the client and the close
method closes the connection with the client. Create a new file and name it
server.py.
# first of all import the socket library
import socket
CLIENT
Now we need something with which a server can interact. We could tenet to
the server like this just to know that our server is working.
Create a new file and name it client.py.
# Import socket module
import socket
# receive data from the server and decoding to get the string.
print(s.recv(1024).decode())
# close the connection
s.close()