Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odd error when using s.recv() in Python

I'm making a program that needs to recieve a connection hash from a server. When I use:

connhash = s.recv(1024)

I get this error:

[Errno 10054] An existing connection was forcibly closed by the remote host

Is this my fault or the servers fault?

Here is some of the code leading up to s.recv()

stringfmt = u'%(user)s;%(host)s:%(port)d'
string = stringfmt % data
structfmt = '!bh'
encoded = string.encode('utf-16BE')
packetbytes = struct.pack(structfmt, 2, len(encoded))+encoded
s.send(packetbytes)
connhash = s.recv(1024)

I am using Python v 2.7

EDIT: This is for Minecraft just so you know.

like image 594
Fixie Avatar asked Nov 03 '22 09:11

Fixie


1 Answers

It sounds like the remote server doesn't like your connection and cuts you off. This could mean you've made a protocol mistake (i.e., the commands you are sending are incorrect), or you may not have logged in successfully, or your IP may have been banned, or many other similar things.

To debug it, you could try using something like telnet to replicate the connection and see where the error occurs (if it doesn't, then there is something wrong with your implementation; if it does, there is something wrong with your understanding of the protocol, or you are blocked from using the server).

Alternatively, use a packet capture tool like Wireshark to look at what packets are being sent and received, and see if that shows the problem.

like image 52
Blair Avatar answered Nov 08 '22 03:11

Blair