Hello! I am making a program which a client and a server send each other message. I want to make it to be cross platform so a linux os can send messages to windows os and versa visa. In the same platform everything works fine but when I want to send to a different platform I came across to an EOF error.
Server
Quote:t socket
import sys
import pickle
import struct
HOST = '192.168.168.116' # Symbolic name, meaning all available interfaces
PORT = 8889 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print('Socket created')
# Bind socket to local host and port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
sys.exit()
print('Socket bind complete')
# Start listening on socket
s.listen(10)
print('Socket now listening')
# now keep talking with the client
while 1:
# wait to accept a connection - blocking call
conn, addr = s.accept()
print('Connected with ' + addr[0] + ':' + str(addr[1]))
size = struct.calcsize("L")
size = conn.recv(size)
size = socket.ntohl(struct.unpack("L", size)[0])
buff = ""
final = ""
while len(buff) < size:
buff = conn.recv(size - len(buff))
final = pickle.loads(buff)
print(final)
s.close()
Client
Quote:import socket
import sys
import pickle
import struct
host = '192.168.168.116'
port = 8889
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setblocking(1)
sock.connect((host, port))
names = ["hello", "john", "hi", 55555, "end"]
buffer = pickle.dumps(names)
value = socket.htonl(len(buffer))
size = struct.pack("L", value)
sock.send(size)
sock.send(buffer)
print(buffer)
The client runs on ubuntu and the server on windows 10. As i have mention when I execute those scripts in the same platform everything works fine