File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 1+ import socket # Import socket module
2+
3+ s = socket .socket () # Create a socket object
4+ host = socket .gethostname () # Get local machine name
5+ port = 12345 # Reserve a port for your service.
6+
7+ s .connect ((host , port ))
8+ print (s .recv (1024 ))
9+ s .close # Close the socket when done
Original file line number Diff line number Diff line change 1+ import socket # Import socket module
2+
3+ s = socket .socket () # Create a socket object
4+ host = socket .gethostname () # Get local machine name
5+ port = 12345 # Reserve a port for your service.
6+ s .bind ((host , port )) # Bind to the port
7+
8+ s .listen (5 ) # Now wait for client connection.
9+ while True :
10+ c , addr = s .accept () # Establish connection with client.
11+ print ('Got connection from' , addr )
12+ c .send ('Thank you for connecting' )
13+ c .close () # Close t
You can’t perform that action at this time.
0 commit comments