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

Client code

parent 94975844
No related branches found
No related tags found
No related merge requests found
...@@ -7,10 +7,35 @@ import socket ...@@ -7,10 +7,35 @@ import socket
HOST = '' HOST = ''
PORT = 3074 PORT = 3074
def start_chat_thread(conn, addr):
t = ChatMsgThread(conn, addr)
t.start()
class ChatMsgThread(Thread):
def __init__(self, conn, addr):
Thread.__init__(self)
self.conn = conn
self.addr = addr
def run(self):
self.conn.sendall(b"Send your message, I will be able to see it here.\n")
while(self.conn._closed):
try:
data = self.conn.recv(2048)
if not data:
self.conn.close()
break
else:
try:
data = data.decode()
print(data)
except:
pass
except:
pass
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#AF - Address Family
#INET - Internet
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT)) s.bind((HOST, PORT))
s.listen() s.listen()
...@@ -19,10 +44,7 @@ while(True): ...@@ -19,10 +44,7 @@ while(True):
#conn - the connection object with the client #conn - the connection object with the client
#addr - array 0 - IP address of the client #addr - array 0 - IP address of the client
# array 1 - The back port with which the connection is established # array 1 - The back port with which the connection is established
print("IP {} connected".format(addr[0]))
print(addr)
conn.sendall(b"Hello, welcome to this workshop")
conn.close()
s.close()
s.close()
\ No newline at end of file
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