Page 1 of 1

Receiving result back from TCP

Posted: Wed Sep 19, 2012 3:52 am
by kmp14
This seems like a simple one, but I am not getting anywhere.

I am using a plugin I created (I think I created it**....Based on Network Event Sender, it has been a couple years) that is simple, it sends a string to a TCP server. It works as expected. I am now trying to read the results that the TCP server sends back based on what string command was sent. I am not getting anywhere. here is what I need to happen:

1. Send a string to a TCP server, TCP server sends back a string result. (Working)
2. Retrieve the result (No idea how to do this) :(
3. If I can make #2 above happen, parse the string result to retrieve info I need from that result, using Python I assume.
4. Use the parsed string for further automation.

#2 is where I am stuck. I assume I may somehow need to modify the plugin that is sending the string to the TCP server in step #1?

Hope this makes sense, any help would be appreciated!

**BTW - I may be WAY wrong on thinking I created the plugin. I know a few years back I was trying to use a base and create/modify an existing network plugin, just not sure at all :)

Re: Receiving result back from TCP

Posted: Wed Sep 19, 2012 5:20 am
by krambriw
It is easy, post a reply with:
- a COPY of the event you want to explore
- specify WHAT data you want to retrieve
- specify HOW you want it formated (as print, as new event....)

BR Walter

Re: Receiving result back from TCP

Posted: Wed Sep 19, 2012 2:19 pm
by kmp14
Thanks Walter,

I am just starting to learn, so bear with me. I don't know python...yet.

Ok, attached is the Plugin I am using. I am pretty sure I "created" it a few years ago, it is a simplified version of the Network Event Sender. All it does is connect to a TCP socket server, and pass a string.

On line 114, it does a socket sendall(). The TCP server that receives the message does it's thing and returns back a result as a string. I may be way off on this, but It doesn't seem that I can get at that returned string via sendall(). I would like to get that string, do some string stuff on it, and pass along that string for use in other EG action.

I hope this is enough info.

Re: Receiving result back from TCP

Posted: Wed Sep 19, 2012 3:12 pm
by krambriw
Hi, no problem. As you say, to send you use sendall like you do in

Code: Select all

sock.sendall(eventString.encode(eg.systemEncoding) + "\n\r")
and to receive you should use recv like this

Code: Select all

rsp = sock.recv(512)
You could just quickly try to modify your code a bit to see if it works:

Code: Select all

sock.sendall(eventString.encode(eg.systemEncoding) + "\n\r")
eg.Wait(0.1) #Give your host a chance to think and reply
rsp = sock.recv(512)
print rsp
Eventually you need to import eg as well but try first without.

BestR Walter

Re: Receiving result back from TCP

Posted: Wed Sep 19, 2012 3:32 pm
by kmp14
Awesome! I figured it was probably something pretty simple. I really need to dig in a learn more python, but in the meantime, thanks for the tip! I will give it a try tonight, and then likely be back with more questions. I know my next one will be how to get the resp out of the plugin and expose it for use as a parm for another action. I figure I need to import eg, etc....I will search the forums for more info.

Thanks!