In this program is help to chat with client to server and server to client to send sms.
there are 2 python programs are run in two different CMD.
Step1: server.py to save these program
import socket
import time
def Main():
host = "172.16.1.81"
port = 8080
mySocket = socket.socket()
mySocket.bind((host,port))
mySocket.listen(1)
print("socket is Listeining")
conn, addr = mySocket.accept()
print ("Connection from: " + str(addr))
while True:
data = conn.recv(1024).decode()
if not data:
break
print ("from connected user: " + str(data))
data = str(data)
print ("Received from User: " + str(data))
data = input("Enter your Message :")
conn.send(data.encode())
conn.close()
if __name__ == '__main__':
Main()
open CMD and run
python server.py
step2: clent_server.py
import socket
def Main():
host = '172.16.1.81'
port = 8080
mySocket = socket.socket()
mySocket.connect((host,port))
message = input("Enter your message: ")
while message != 'q':
mySocket.send(message.encode())
data = mySocket.recv(1024).decode()
print ('Received from server: ' + data)
data = input("Enter uour mesage: ")
mySocket.close()
if __name__ == '__main__':
Main()
there are 2 python programs are run in two different CMD.
Step1: server.py to save these program
import socket
import time
def Main():
host = "172.16.1.81"
port = 8080
mySocket = socket.socket()
mySocket.bind((host,port))
mySocket.listen(1)
print("socket is Listeining")
conn, addr = mySocket.accept()
print ("Connection from: " + str(addr))
while True:
data = conn.recv(1024).decode()
if not data:
break
print ("from connected user: " + str(data))
data = str(data)
print ("Received from User: " + str(data))
data = input("Enter your Message :")
conn.send(data.encode())
conn.close()
if __name__ == '__main__':
Main()
open CMD and run
python server.py
step2: clent_server.py
import socket
def Main():
host = '172.16.1.81'
port = 8080
mySocket = socket.socket()
mySocket.connect((host,port))
message = input("Enter your message: ")
while message != 'q':
mySocket.send(message.encode())
data = mySocket.recv(1024).decode()
print ('Received from server: ' + data)
data = input("Enter uour mesage: ")
mySocket.close()
if __name__ == '__main__':
Main()
open another CMD run this program
python client_server.py
No comments:
Post a Comment