Skip to content
Snippets Groups Projects
Commit f73a98a4 authored by Sibidharan's avatar Sibidharan :speech_balloon:
Browse files

Client code

parent 51479346
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
#Hostname: learn.selfmade.ninja
import socket
from threading import Thread
HOST = ''
PORT = 3074
......@@ -16,15 +17,16 @@ class ChatMsgThread(Thread):
Thread.__init__(self)
self.conn = conn
self.addr = addr
print("IP {} connected".format(addr[0]))
def run(self):
self.conn.sendall(b"Send your message, I will be able to see it here.\n")
while(self.conn._closed):
while(True):
try:
data = self.conn.recv(2048)
if not data:
self.conn.close()
break
continue
else:
try:
data = data.decode()
......@@ -44,7 +46,7 @@ while(True):
#conn - the connection object with the client
#addr - array 0 - IP address of the client
# array 1 - The back port with which the connection is established
start_chat_thread(conn, addr)
s.close()
......@@ -15,13 +15,13 @@ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect((HOST, PORT))
print(s.recv(2048).decode())
while(True):
msg = input("Message: ")
if(msg == "quit"):
break
msg = name + ": " + msg
s.send(msg.encode())
s.sendall(msg.encode())
s.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment