Python Forum
Socket crossplatform EOF error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Socket crossplatform EOF error
#1


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
Reply
#2
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?
Reply
#3
I use windows 10 on my lockal pc and on a vm ubuntu 16
Reply
#4
Show us the error.
For learning purposes pickle is ok but it's considering dangerous. Use json to transmit messages. Or even plain text
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Instance of 'socket' has no 'error' member fedex03 1 2,904 May-13-2020, 03:23 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020