1

I have an issue with a script I want to create for a Raspberry Pi using Python.

To test the script I'm running Python 3.6 on a Windows 64 bit machine. I want to send "1" to my local address (192.168.1.101 / 127.0.0.1) on port 1235, using TCP.

When I use putty in RAW mode, i can send this data to my server and I get the right response instantly.

But when I try to do this using Python on Windows I get a steady 2 minute delay. I can also see the command is only received by the server 2 minute after I send it. And after those two minutes I get an instant reply.

The code:

import socket

message = '\x31'.encode()    
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    
s.connect(('192.168.1.101', 1235))    
s.send(message) ; print ("send ready") ; data = s.recv(80) ; s.close(); print ("received"), repr(data)

#forgive me the ; ... I'm on a command line for testing.
#response is:

1

send ready

#2 minute delay

("None, "b"140,1,1,test\\r\n'")

I have been trying things like SOCKET_DGRAM, RAW TCP NO DELAY, SO_SNDBUF, etc., but I can't find where this is coming from.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Looks like a timeout. What if you test with `s.recv(1)` ? – Danny_ds Jun 21 '18 at 23:44
  • What is listening on port 1235? and does it require a line terminator? – user207421 Jun 21 '18 at 23:59
  • Hi, thanks for the quick replies. I asked some of my collegeaus at work as well. I already tried '\x31\x0a' as message... but there was missing a complete Cr,LF. So with the message being '\x31\x0d\x0a' it works. – Sytse Elzinga Jun 22 '18 at 14:58

0 Answers0