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


Messages In This Thread
Socket crossplatform EOF error - by John - Dec-20-2017, 09:20 AM
RE: Socket crossplatform EOF error - by nilamo - Dec-20-2017, 07:18 PM
RE: Socket crossplatform EOF error - by John - Dec-20-2017, 09:09 PM
RE: Socket crossplatform EOF error - by wavic - Dec-21-2017, 05:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Instance of 'socket' has no 'error' member fedex03 1 2,920 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