Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Receiving result back from TCP

Questions and comments specific to a particular plugin should go here.
Post Reply
kmp14
Posts: 6
Joined: Thu Dec 29, 2011 5:25 pm

Receiving result back from TCP

Post 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 :)
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Receiving result back from TCP

Post 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
kmp14
Posts: 6
Joined: Thu Dec 29, 2011 5:25 pm

Re: Receiving result back from TCP

Post 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.
Attachments
__init__.py
(4.49 KiB) Downloaded 200 times
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Receiving result back from TCP

Post 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
kmp14
Posts: 6
Joined: Thu Dec 29, 2011 5:25 pm

Re: Receiving result back from TCP

Post 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!
Post Reply