Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def readInt(sock):
- data = sock.recv(4)
- data = struct.unpack("!i", data)[0]
- return data
- def sendInt(sock, toSend):
- sock.send(struct.pack("!i", toSend))
- def sendChar(sock, toSend):
- sock.send(struct.pack("!c", toSend.encode('ascii')))
- def readChar(sock):
- data = sock.recv(1)
- data = struct.unpack("!c", data)[0].decode('ascii')
- return data
- def sendIntArray(sock, toSend):
- sendInt(sock, len(toSend))
- for value in toSend:
- sendInt(sock, value)
- def sendCharArray(sock, toSend):
- sendInt(sock, len(toSend))
- for value in toSend:
- sendChar(sock, value)
- def readIntArray(sock):
- buff = []
- length = readInt(sock)
- for i in range(length):
- buff.append(readInt(sock))
- return buff
- def readCharArray(sock):
- buff = ""
- length = readInt(sock)
- for i in range(length):
- buff+=readChar(sock)
- return buff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement