Quantcast
Viewing all articles
Browse latest Browse all 120

Use Python For Socket Programming To Connect Two or More PCs To Share A Text File.

========= To server.py File =======
 #!/usr/bin/python           # This is server.py file

import socket          # Import socket module
import sys

s = socket.socket()     # Create a socket object
host = '192.168.2.232'
port = 4444             # Reserve a port for your service.
s.bind((host, port))    # Bind to the port

s.listen(5) #Now wait for client connection.
fileToSend = open("ToSend.txt","r")
content = fileToSend.read()
while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
c.sendall(content)
c.close() # Close the connection
fileToSend.close()
============ To File.txt File ============
HELLO.....
============ OUTPUT ============
[hnpandya@localhost ~]$ python server.py
Got connection from ('192.168.2.233', 40628).

Viewing all articles
Browse latest Browse all 120

Trending Articles