Problem with streamsocket receiving
so I have no issues sending data from pharo to python but I have a problem recieving data from python here is my method sendMessage: aString |stream errString isDataAvailable | stream := SocketStream openConnectionToHostNamed: '127.0.0.1' port: 4000 . stream sendCommand: aString. isDataAvailable := stream isDataAvailable . isDataAvailable inspect. isDataAvailable ifTrue: [ errString := stream nextLineCrLf . errString inspect. errString = '' ifFalse: [self error: errString.]] . stream close. I have used telnet to test the connection , telnet can receive the data fine and it displays it fine. I have encode the data as bytestring from python with ascii encoding and added both a carriage return and a line feed in the end ? whats wrong ? I tried most method in socket stream even upToEnd message and none gives back any data. What am I doing wrong ?
Kilon, I can't see any direct error in your code (on the client side, I don't known about the server). Consider this (do it): | stream | stream := SocketStream openConnectionToHostNamed: 'zn.stfx.eu' port: 80. stream sendCommand: 'GET / HTTP1.1', String crlf. stream upToEnd inspect . stream close. Client-side TCP is pretty simple. #sendCommand: does a #flush after adding a CRLF (we need two here). HTH, Sven PS: There is no need to do #isDataAvailable, reading a socket stream blocks while waiting for data (within the timeout). On 26 Jul 2014, at 01:04, kilon alios <kilon.alios@gmail.com> wrote:
so I have no issues sending data from pharo to python but I have a problem recieving data from python
here is my method
sendMessage: aString
|stream errString isDataAvailable | stream := SocketStream openConnectionToHostNamed: '127.0.0.1' port: 4000 . stream sendCommand: aString. isDataAvailable := stream isDataAvailable . isDataAvailable inspect. isDataAvailable ifTrue: [ errString := stream nextLineCrLf . errString inspect. errString = '' ifFalse: [self error: errString.]] .
stream close.
I have used telnet to test the connection , telnet can receive the data fine and it displays it fine. I have encode the data as bytestring from python with ascii encoding and added both a carriage return and a line feed in the end ? whats wrong ?
I tried most method in socket stream even upToEnd message and none gives back any data.
What am I doing wrong ?
yes you are correct its a problem at the python side. I tested with telnet and it seems it cannot send data. About your PS i am using isDataAvailable because I don't want the socket to go into a block mode, I want to just receive what already has become available to the socket. I tested with telnet and it works exactly as I want. That part of the code is too simple and probably will change in the future so its definitely not a final solution. On Sat, Jul 26, 2014 at 11:37 AM, Sven Van Caekenberghe <sven@stfx.eu> wrote:
Kilon,
I can't see any direct error in your code (on the client side, I don't known about the server).
Consider this (do it):
| stream | stream := SocketStream openConnectionToHostNamed: 'zn.stfx.eu' port: 80. stream sendCommand: 'GET / HTTP1.1', String crlf. stream upToEnd inspect . stream close.
Client-side TCP is pretty simple. #sendCommand: does a #flush after adding a CRLF (we need two here).
HTH,
Sven
PS: There is no need to do #isDataAvailable, reading a socket stream blocks while waiting for data (within the timeout).
On 26 Jul 2014, at 01:04, kilon alios <kilon.alios@gmail.com> wrote:
so I have no issues sending data from pharo to python but I have a problem recieving data from python
here is my method
sendMessage: aString
|stream errString isDataAvailable | stream := SocketStream openConnectionToHostNamed: '127.0.0.1' port: 4000 . stream sendCommand: aString. isDataAvailable := stream isDataAvailable . isDataAvailable inspect. isDataAvailable ifTrue: [ errString := stream nextLineCrLf . errString inspect. errString = '' ifFalse:
[self error: errString.]] .
stream close.
I have used telnet to test the connection , telnet can receive the data
fine and it displays it fine. I have encode the data as bytestring from python with ascii encoding and added both a carriage return and a line feed in the end ? whats wrong ?
I tried most method in socket stream even upToEnd message and none gives
back any data.
What am I doing wrong ?
You know at times I admire how stupid I can be. So the problem was not the fault of Blender , of Python or of Pharoâ. It was me , me and me :D I was reading the Python 2 docs on sending data via sockets when I should be reading the Python 3 docs , because Blender uses Python 3 and in Python 2 data is sent as string and in Python 3 data is sent as binary.All I had to do was to convert the string to a binary . I would have seen the error but unfortunately because of a strange bug in Blender I cannot run it from terminal and so it does not display any errors :D So yes problem solved and off I go to next stupid mistake. Coding is such a humiliating experience :D
ok next question . what kind of encoding does StreamSocket expects for incoming messages because it does not seem to accept the python encoding I also tried utf-8 with no success. Basically I encode a python string to a binary string. Is there a specific encoding for the bytes it expect in order to accept the incoming message ?
kilon alios wrote:
You know at times I admire how stupid I can be. So the problem was not the fault of Blender , of Python or of Pharoâ. It was me , me and me :D
I was reading the Python 2 docs on sending data via sockets when I should be reading the Python 3 docs , because Blender uses Python 3 and in Python 2 data is sent as string and in Python 3 data is sent as binary.All I had to do was to convert the string to a binary . I would have seen the error but unfortunately because of a strange bug in Blender I cannot run it from terminal and so it does not display any errors :D
So yes problem solved and off I go to next stupid mistake. Coding is such a humiliating experience :D
"troubleshooting" => The art of stepping backwards through your assumptions :)
well it seems plain encoding worked. Now the next issue is how to synchronise error reporting between blender and pharo. I am receiving the data from the socket with some lag. Again most likely I am doing something wrong. Anyway thanks all for your help. On Sat, Jul 26, 2014 at 5:16 PM, Ben Coman <btc@openinworld.com> wrote:
kilon alios wrote:
You know at times I admire how stupid I can be. So the problem was not the fault of Blender , of Python or of Pharoâ. It was me , me and me :D
I was reading the Python 2 docs on sending data via sockets when I should be reading the Python 3 docs , because Blender uses Python 3 and in Python 2 data is sent as string and in Python 3 data is sent as binary.All I had to do was to convert the string to a binary . I would have seen the error but unfortunately because of a strange bug in Blender I cannot run it from terminal and so it does not display any errors :D
So yes problem solved and off I go to next stupid mistake. Coding is such a humiliating experience :D
"troubleshooting" => The art of stepping backwards through your assumptions :)
participants (3)
-
Ben Coman -
kilon alios -
Sven Van Caekenberghe