Skip to content

Instantly share code, notes, and snippets.

@TestPrab
Last active April 20, 2020 16:04
Show Gist options
  • Select an option

  • Save TestPrab/12e6042e6b2c56e53e5700e35055c0a9 to your computer and use it in GitHub Desktop.

Select an option

Save TestPrab/12e6042e6b2c56e53e5700e35055c0a9 to your computer and use it in GitHub Desktop.
import socket
import sys
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect((socket.gethostname(),1235))
print(" Connection Establised ")
def Option():
opt=input("Enter 1 if you wanna send message ")
client.send(opt.encode("ascii"))
if opt=="1":
Input()
else:
ouput()
def Input():
msg=input("Enter your message\n")
client.send(msg.encode("ascii"))
optt=client.recv(1024).decode()
if optt=="1":
#print("Got it You wanna send me okk !!")
ouput()
else:
#print(" Okk I will send you ")
Input()
def ouput():
full_msg=" "
msg=" "
print("Message Recieved :")
while True:
msg=client.recv(2048).decode("ascii")
if msg=="000":
print("Closing The chats ")
client.close()
sys.exit(1)
#print("This is a test message ")
#print(len(msg),msg)
if len(msg)<=0:
break
else:
full_msg=full_msg+msg
print(full_msg)
Option()
ouput()
import socket
import sys
server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind((socket.gethostname(),1235))
server.listen(5)
client,add=server.accept()
print(f"Successfully Connected to address {add}")
Disconnect="000"
def Option():
opt=input("Enter 1 if you wanna send message ")
client.send(opt.encode("ascii"))
if opt=="1":
Input()
else:
ouput()
def Input():
msg=input("Enter your message\n")
client.send(msg.encode("ascii"))
optt=client.recv(1024).decode()
if optt=="1":
#print("Got it You wanna send me okk !!")
ouput()
else:
# print(" Okk I will send you ")
Input()
def ouput():
full_msg=" "
msg=" "
print("Message recieved:")
while True:
msg=client.recv(2048).decode("ascii")
if msg=="000":
print("Closing The chats ")
client.close()
sys.exit(1)
#print("This is a test message ")
#print(len(msg),msg)
if len(msg)<=0:
break
else:
full_msg=full_msg+msg
print(full_msg)
Option()
Input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment