Skip to content
Permalink
Browse files
Add files via upload
  • Loading branch information
bhusala committed Jul 24, 2020
0 parents commit b614a1bb95aa5c4192337d25cca91face5f82207
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
@@ -0,0 +1,29 @@
import socket,pickle

HEADERSIZE = 10

s= socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((socket.gethostname(),1234))

while True:
full_msg = b''
new_msg = True
while True:
msg= s.recv(18)
if new_msg:
print(f'new message length: {msg[:HEADERSIZE]}')
msglen = int(msg[:HEADERSIZE])
new_msg = False

full_msg+=msg
if len(full_msg)- HEADERSIZE == msglen:
print("Full msg recvd")
print(full_msg[HEADERSIZE:])

d= pickle.loads(full_msg[HEADERSIZE:])
print(d)
new_msg = True
full_msg =b''

print(full_msg)

@@ -0,0 +1,18 @@
import socket,time,pickle

HEADERSIZE = 10

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((socket.gethostname(),1234))
s.listen(5)

while True:
clientsocket, address = s.accept()
print(f"Connection from {address} has been established! ")

d = {1:"Hey", 2:"There"}
msg = pickle.dumps(d)

msg = bytes(f'{len(msg):<{HEADERSIZE}}',"utf-8")+msg

clientsocket.send(msg)

0 comments on commit b614a1b

Please sign in to comment.