From: Jordan Apgar on
I have a simple tcp server and client where the server sits and waits
for a message and then processes it, my client sends its first message
to the server. On the server I receive:

socket.error: [Errno 107] Transport endpoint is not connected
when calling
msg = self.socket.recv(self.buffer)

My client receives the error:
socket.error: [Errno 104] Connection reset by peer
when calling
msg = self.socket.recv(self.buffer)

I was working on the server and client over the weekend and sending
and receiving worked fine, I wanted to debug a few things and I get
this when I try to run it (no changes made from what I had on the
weekend)
From: Steve Holden on
Jordan Apgar wrote:
> I have a simple tcp server and client where the server sits and waits
> for a message and then processes it, my client sends its first message
> to the server. On the server I receive:
>
> socket.error: [Errno 107] Transport endpoint is not connected
> when calling
> msg = self.socket.recv(self.buffer)
>
> My client receives the error:
> socket.error: [Errno 104] Connection reset by peer
> when calling
> msg = self.socket.recv(self.buffer)
>
> I was working on the server and client over the weekend and sending
> and receiving worked fine, I wanted to debug a few things and I get
> this when I try to run it (no changes made from what I had on the
> weekend)

My car has this problem. It makes a noise when it rolls along the road.
I've brought the wheel for you to take a look at, can you fix it,
please? ;-)

A little more context might be helpful - at least the error traceback
and the code that makes the socket calls. I presume you are using TCP
judging by the client error message. This implies the server isn't
listening. Have you correctly bound the socket to an IP address and port
before issuing an accept() call?

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

From: Jean-Michel Pichavant on
Jordan Apgar wrote:
> I have a simple tcp server and client where the server sits and waits
> for a message and then processes it, my client sends its first message
> to the server. On the server I receive:
>
> socket.error: [Errno 107] Transport endpoint is not connected
> when calling
> msg = self.socket.recv(self.buffer)
>
> My client receives the error:
> socket.error: [Errno 104] Connection reset by peer
> when calling
> msg = self.socket.recv(self.buffer)
>
> I was working on the server and client over the weekend and sending
> and receiving worked fine, I wanted to debug a few things and I get
> this when I try to run it (no changes made from what I had on the
> weekend)
>
Unless you want to know more about net coding, I would suggest to use
libraries for that.
Pyro or xmlrpclib are among the most used.

Then if you have any connection problem, that's because there is a
connection problem. Not because you mess up with your net code.

JM


From: Jordan Apgar on
I found my car ;)

here's the server:

class commServer:
"""Class to hold a tcp server and interact with with it
allows for a wrapper around socket class to keep code clean"""

def __init__ (self, host, hostid, port, buff =1024):
self.host = host
self.hostid = hostid #id of the server
self.port = port
self.buffer = buff
self.socket = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
self.conn = None
self.addr = None

def bindServ(self):
"""Connect to the server specified by self.host, self.port"""
self.socket.bind((self.host, self.port))
def closeConn(self):
"""Disconnect from the server connected to"""
self.conn.close()
def listen(self):
self.socket.listen(1)
def accept(self):
self.conn, self.addr = self.socket.accept()

#lets you send a string msg to the server
def sendMSG(self, msg):
self.conn.send(msg)
#lets you receive data from the server
def recvMSG(self):
msg = self.socket.recv(self.buffer)
if msg == "": #if the client disconnected let's not throw
return False
else:
return msg


class Negotiator:
"""Negotiator for the server handles all communication with the
client to
verify the server and prepare the file the client wants for
download"""
def __init__(self, host, hostid, port, rsa_key):
self.server = commServer(host,hostid,port)

def Negotiate(self):
self.server.bindServ()
self.server.listen()
self.server.accept()

#Plan on being asked for server confirmation
clmsg = self.server.recvMSG() # it fails right here on the
server


calling the Server Negotiator as:
host = "127.0.0.1"
port = 8005
HOSTID = a string
key = an RSA key
servernegotiator = Negotiator(host,HostID, port, key)
if servernegotiator.Negotiate() == False:
print "something went wrong"
print "Done"



for the client it is:
class commClient:
"""Class to hold a tcp client and interact with with it
allows for a wrapper around socket class to keep code clean"""

def __init__ (self, host, hostid, port, buff =1024):
self.host = host
self.hostid = hostid #id of the server
self.port = port
self.buffer = buff
self.socket = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)

def connectServ(self):
"""Connect to the server specified by self.host, self.port"""
self.socket.connect((self.host, self.port))
def disconnServ(self):
"""Disconnect from the server connected to"""
self.socket.close()

#lets you send a string msg to the server
def sendMSG(self, msg):
self.socket.send(msg)
#lets you receive data from the server
def recvMSG(self):
msg = self.socket.recv(self.buffer)
if msg == "": #if the server disconnected let's not throw
something later
return False
else:
return msg



class Negotiator:
"""The Negotiator handles all communications and message handling
necessary for verifying the server, and that the file is available
to
download"""
def __init__(self, host, hostid, port, rsa_key):
"""client should be a commClient object that has not been
connected
to the server."""
self.client = commClient(host, hostid, port)
self.clientKey = rsa_key
self.serverKey = None
self.CScipher = None #AES cipher for client -> server
self.SCcipher = None #AES cipher for server -> client
self.CShalves = None #tuple for random halves by client
self.SChalves = None #tuple for random halves by server
self.file = None


def Negotiate(self, fname):
"""Contact the server, verify the server,
negotiates for a file to be downloaded by the client. It
returns
the file name to be downloaded, and the cipher to decrypt
it."""

self.client.connectServ()
print "connected"

#tell the server you want to connect
clmsg = message(CONN, (self.client.getHost(),
self.client.getHostID())) #message acts
as a wrapper around a message type and the data for the type
self.client.sendMSG(clmsg.getSendable()) # here is were it
fails

the Negotiator is called as:
host = "127.0.0.1"
port = 8005
HOSTID is the same string as before
key is an RSA key
clientnegotiator = Negotiator(host, HostID, port, key)
filename = clientnegotiator.Negotiate("hostid")

the stack traces are:
Server side:
Traceback (most recent call last):
File "Server.py", line 17, in <module>
if servernegotiator.Negotiate() == False:
File "/home/twistedphrame/Desktop/communication/
ServerNegotiator.py", line 184, in Negotiate
clmsg = self.server.recvMSG()
File "/home/twistedphrame/Desktop/communication/
ServerNegotiator.py", line 67, in recvMSG
msg = self.socket.recv(self.buffer)
socket.error: [Errno 107] Transport endpoint is not connected

Client Side:
File "Client.py", line 17, in <module>
filename = clientnegotiator.Negotiate("hostid")
File "/home/twistedphrame/Desktop/communication/
ClientNegotiator.py", line 209, in Negotiate
srvmsg = self.client.recvMSG()
File "/home/twistedphrame/Desktop/communication/
ClientNegotiator.py", line 55, in recvMSG
msg = self.socket.recv(self.buffer)
socket.error: [Errno 104] Connection reset by peer


From: Jean-Michel Pichavant on
Jordan Apgar wrote:
> I found my car ;)
>
> here's the server:
>
> class commServer:
> """Class to hold a tcp server and interact with with it
> allows for a wrapper around socket class to keep code clean"""
>
> def __init__ (self, host, hostid, port, buff =1024):
> self.host = host
> self.hostid = hostid #id of the server
> self.port = port
> self.buffer = buff
> self.socket = socket.socket(socket.AF_INET,
> socket.SOCK_STREAM)
> self.conn = None
> self.addr = None
>
> def bindServ(self):
> """Connect to the server specified by self.host, self.port"""
> self.socket.bind((self.host, self.port))
> def closeConn(self):
> """Disconnect from the server connected to"""
> self.conn.close()
> def listen(self):
> self.socket.listen(1)
> def accept(self):
> self.conn, self.addr = self.socket.accept()
>
> #lets you send a string msg to the server
> def sendMSG(self, msg):
> self.conn.send(msg)
> #lets you receive data from the server
> def recvMSG(self):
> msg = self.socket.recv(self.buffer)
> if msg == "": #if the client disconnected let's not throw
> return False
> else:
> return msg
>
>
> class Negotiator:
> """Negotiator for the server handles all communication with the
> client to
> verify the server and prepare the file the client wants for
> download"""
> def __init__(self, host, hostid, port, rsa_key):
> self.server = commServer(host,hostid,port)
>
> def Negotiate(self):
> self.server.bindServ()
> self.server.listen()
> self.server.accept()
>
> #Plan on being asked for server confirmation
> clmsg = self.server.recvMSG() # it fails right here on the
> server
>
>
> calling the Server Negotiator as:
> host = "127.0.0.1"
> port = 8005
> HOSTID = a string
> key = an RSA key
> servernegotiator = Negotiator(host,HostID, port, key)
> if servernegotiator.Negotiate() == False:
> print "something went wrong"
> print "Done"
>
>
>
> for the client it is:
> class commClient:
> """Class to hold a tcp client and interact with with it
> allows for a wrapper around socket class to keep code clean"""
>
> def __init__ (self, host, hostid, port, buff =1024):
> self.host = host
> self.hostid = hostid #id of the server
> self.port = port
> self.buffer = buff
> self.socket = socket.socket(socket.AF_INET,
> socket.SOCK_STREAM)
>
> def connectServ(self):
> """Connect to the server specified by self.host, self.port"""
> self.socket.connect((self.host, self.port))
> def disconnServ(self):
> """Disconnect from the server connected to"""
> self.socket.close()
>
> #lets you send a string msg to the server
> def sendMSG(self, msg):
> self.socket.send(msg)
> #lets you receive data from the server
> def recvMSG(self):
> msg = self.socket.recv(self.buffer)
> if msg == "": #if the server disconnected let's not throw
> something later
> return False
> else:
> return msg
>
>
>
> class Negotiator:
> """The Negotiator handles all communications and message handling
> necessary for verifying the server, and that the file is available
> to
> download"""
> def __init__(self, host, hostid, port, rsa_key):
> """client should be a commClient object that has not been
> connected
> to the server."""
> self.client = commClient(host, hostid, port)
> self.clientKey = rsa_key
> self.serverKey = None
> self.CScipher = None #AES cipher for client -> server
> self.SCcipher = None #AES cipher for server -> client
> self.CShalves = None #tuple for random halves by client
> self.SChalves = None #tuple for random halves by server
> self.file = None
>
>
> def Negotiate(self, fname):
> """Contact the server, verify the server,
> negotiates for a file to be downloaded by the client. It
> returns
> the file name to be downloaded, and the cipher to decrypt
> it."""
>
> self.client.connectServ()
> print "connected"
>
> #tell the server you want to connect
> clmsg = message(CONN, (self.client.getHost(),
> self.client.getHostID())) #message acts
> as a wrapper around a message type and the data for the type
> self.client.sendMSG(clmsg.getSendable()) # here is were it
> fails
>
> the Negotiator is called as:
> host = "127.0.0.1"
> port = 8005
> HOSTID is the same string as before
> key is an RSA key
> clientnegotiator = Negotiator(host, HostID, port, key)
> filename = clientnegotiator.Negotiate("hostid")
>
> the stack traces are:
> Server side:
> Traceback (most recent call last):
> File "Server.py", line 17, in <module>
> if servernegotiator.Negotiate() == False:
> File "/home/twistedphrame/Desktop/communication/
> ServerNegotiator.py", line 184, in Negotiate
> clmsg = self.server.recvMSG()
> File "/home/twistedphrame/Desktop/communication/
> ServerNegotiator.py", line 67, in recvMSG
> msg = self.socket.recv(self.buffer)
> socket.error: [Errno 107] Transport endpoint is not connected
>
> Client Side:
> File "Client.py", line 17, in <module>
> filename = clientnegotiator.Negotiate("hostid")
> File "/home/twistedphrame/Desktop/communication/
> ClientNegotiator.py", line 209, in Negotiate
> srvmsg = self.client.recvMSG()
> File "/home/twistedphrame/Desktop/communication/
> ClientNegotiator.py", line 55, in recvMSG
> msg = self.socket.recv(self.buffer)
> socket.error: [Errno 104] Connection reset by peer
>
>
>
http://docs.python.org/library/socketserver.html

JM