Python Forum

Full Version: Socket crossplatform EOF error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


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
You have no problem when they're both on the same platform? Or when they're both running on the same machine?

So it works fine, if the server and client are two different physical machines, but both running the same OS? Can you share the traceback?
I use windows 10 on my lockal pc and on a vm ubuntu 16
Show us the error.
For learning purposes pickle is ok but it's considering dangerous. Use json to transmit messages. Or even plain text