Author Topic: TCP Plugin  (Read 33763 times)

0 Members and 2 Guests are viewing this topic.

Scitz0

  • Jr. Member
  • **
  • Posts: 11
  • Karma: 0
    • View Profile
Re: TCP Plugin
« Reply #75 on: November 22, 2013, 08:33:42 AM »
Ok I added \x0D\x0A to the terminator field and removed the disconnect action
I left the command as @MAIN:VOL=?\x0D\x0A and no delays.

I then ran the command but I dont get any respons, waited five minutes.

According to iRule support forum Yamaha receivers automatically drop the connection after 45s if you dont keep sending keep alive messages.
I cant see any event in history log that it terminates the tcp connection though.
I dont get anything after sending write action that relates to the tcp plugin now checking 10min later.

Scitz0

  • Jr. Member
  • **
  • Posts: 11
  • Karma: 0
    • View Profile
Re: TCP Plugin
« Reply #76 on: November 22, 2013, 08:50:17 AM »
Removed terminate code from connect just for test and got this.
Tried two times, the first time I got two exceptions and second time only the last exception.

Code: [Select]
2013-11-22 13:46:08 56 doCommand:test
2013-11-22 13:46:08 56 action repeat set to: 1
2013-11-22 13:46:08 56 Action:  Tcp.Client.Connect - test&&192.168.0.4&&50000&&&&testEvent
2013-11-22 13:46:08 56 [action] Tcp.Client.Connect:test&&192.168.0.4&&50000&&&&testEvent

2013-11-22 13:46:08 56 [plugin] TcpMic: TCP.ClientError: System.InvalidOperationException: The stream does not support reading.
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
2013-11-22 13:46:08 56 [vcevent] TCP.ClientError.test

2013-11-22 13:46:08 56 [vcevent] TCP.StartListen.test

2013-11-22 13:46:08 56 action repeat set to: 1
2013-11-22 13:46:08 56 Action:  Tcp.Client.Write - test&&@MAIN:VOL=?\x0D\x0A
2013-11-22 13:46:08 56 [action] Tcp.Client.Write:test&&@MAIN:VOL=?\x0D\x0A

2013-11-22 13:46:08 56 [plugin] TcpMic: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
2013-11-22 13:46:08 56 [vcevent] TCP.ClientError.test

2013-11-22 13:46:08 56 [vcevent] TCP.EndListenLoop.test

2013-11-22 13:46:48 882 doCommand:test
2013-11-22 13:46:48 882 action repeat set to: 1
2013-11-22 13:46:48 882 Action:  Tcp.Client.Connect - test&&192.168.0.4&&50000&&&&testEvent
2013-11-22 13:46:48 882 [action] Tcp.Client.Connect:test&&192.168.0.4&&50000&&&&testEvent

2013-11-22 13:46:48 882 [vcevent] TCP.StartListen.test

2013-11-22 13:46:48 882 action repeat set to: 1
2013-11-22 13:46:48 882 Action:  Tcp.Client.Write - test&&@MAIN:VOL=?\x0D\x0A
2013-11-22 13:46:48 882 [action] Tcp.Client.Write:test&&@MAIN:VOL=?\x0D\x0A

2013-11-22 13:46:48 882 [plugin] TcpMic: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
2013-11-22 13:46:48 882 [vcevent] TCP.ClientError.test

2013-11-22 13:46:48 882 [vcevent] TCP.EndListenLoop.test

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin
« Reply #77 on: November 22, 2013, 08:51:21 AM »
Please post XML commands and a log of the current setup with terminators, sending a few times. I understand you are having feedback issues but are your commands like set volume working?

Do you have problems sending IR with the itach?  I never had any problems with it and I also get feedback from it working perfectly because that is what I use to learn IR codes.

Scitz0

  • Jr. Member
  • **
  • Posts: 11
  • Karma: 0
    • View Profile
Re: TCP Plugin
« Reply #78 on: November 22, 2013, 08:56:54 AM »
I could never figure out how to process feedback event in the same command as the one sending the write so this is how I did it:

Notice that I have now changed and readded terminator to connect and removed it from the write itself.

Sending iTach workes without any issues, though I dont use feedback with iTach.

Code: [Select]
<command id="570" name="test" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>Tcp.Client.Connect</cmdType>
                <cmdString>test&amp;&amp;192.168.0.4&amp;&amp;50000&amp;&amp;\x0D\x0A&amp;&amp;testEvent</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Tcp.Client.Write</cmdType>
                <cmdString>test&amp;&amp;@MAIN:VOL=?</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
        </command>
        <command id="571" name="testOSD" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>OSD.ShowText</cmdType>
                <cmdString>Payload: {1}</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <event>testEvent</event>
        </command>

Scitz0

  • Jr. Member
  • **
  • Posts: 11
  • Karma: 0
    • View Profile
Re: TCP Plugin
« Reply #79 on: November 22, 2013, 08:59:45 AM »
Hitting execute with a few seconds delay give me client reconnect errors every time but this my be correct as I dont close the connection?

Code: [Select]
2013-11-22 13:57:29 953 doCommand:test
2013-11-22 13:57:29 953 action repeat set to: 1
2013-11-22 13:57:29 953 Action:  Tcp.Client.Connect - test&&192.168.0.4&&50000&&\x0D\x0A&&testEvent
2013-11-22 13:57:29 953 [action] Tcp.Client.Connect:test&&192.168.0.4&&50000&&\x0D\x0A&&testEvent

2013-11-22 13:57:29 953 [plugin] TcpMic: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall. ---> System.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
2013-11-22 13:57:29 953 [vcevent] TCP.ClientError.test

2013-11-22 13:57:29 953 [vcevent] TCP.StartListen.test

2013-11-22 13:57:29 953 action repeat set to: 1
2013-11-22 13:57:29 953 Action:  Tcp.Client.Write - test&&@MAIN:VOL=?
2013-11-22 13:57:29 953 [action] Tcp.Client.Write:test&&@MAIN:VOL=?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin
« Reply #80 on: November 22, 2013, 09:39:42 AM »
In the command you just posted you don't appear to be sending the command correctly.  You are sending

Code: [Select]
@MAIN:VOL=?
but shouldn't you be sending

Code: [Select]
@MAIN:VOL=?\x0D\x0A
When you specify the terminator in the connect action, that is the terminator used to detect the end of an incoming message.  It is not used for sending.

Also, if possibly please copy and paste a single command or a single group from the tree.  I was not able to copy and paste your xml code into my tree the way you posted it, with two commands, not in a group.

We are still in the diagnostic phase.  When we get it sorted out (if) and working we can explore other options, like possibly getting feedback directly in a call to tcp.single actions, where you simply specify the maximum time you want to wait.  I was thinking about doing this anyway and it seems like something that would make your life easier.  But I'd still like to try to get it working as is, since I won't have time to any updates for a while.

Scitz0

  • Jr. Member
  • **
  • Posts: 11
  • Karma: 0
    • View Profile
Re: TCP Plugin
« Reply #81 on: November 22, 2013, 10:42:15 AM »
I was able to get feedback on all my repetitive executes using this:
I then waited 20min or so and tried again, first I received and exception och the first couple of tries, then I got the feedback RESTRICTED, after this hitting execute return the correct feedback every time. So i tried again, waited a couple of minutes or so and again got exception on first couple of tries and then I got the correct feedback. Maybe the receiver force close the connection but the TCP plugin still tries to keep it open and then it takes a while for it to reestablish the connection correctly?
Made a third test and waited about 3m after last successful feedback and this time I was able to continue without any issues, strange.

Code: [Select]
<commandGroup open="True" name="Yamaha (Test)" enabled="True" prefix="" priority="0" requiredProcess="" description="">
        <command id="581" name="test" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>Tcp.Client.Connect</cmdType>
                <cmdString>test&amp;&amp;192.168.0.4&amp;&amp;50000&amp;&amp;\x0D\x0A&amp;&amp;testEvent</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Tcp.Client.Write</cmdType>
                <cmdString>test&amp;&amp;@MAIN:VOL=?\x0D\x0A</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
        </command>
        <command id="575" name="testOSD" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>OSD.ShowText</cmdType>
                <cmdString>Payload: {1}</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <event>testEvent</event>
        </command>
    </commandGroup>

Though I get an exception on repeated executions for client.connect
Code: [Select]
2013-11-22 14:47:05 889 doCommand:test
2013-11-22 14:47:05 889 action repeat set to: 1
2013-11-22 14:47:05 889 Action:  Tcp.Client.Connect - test&&192.168.0.4&&50000&&\x0D\x0A&&testEvent
2013-11-22 14:47:05 889 [action] Tcp.Client.Connect:test&&192.168.0.4&&50000&&\x0D\x0A&&testEvent

Exceptions I receive sometimes(different it seems):
[code]2013-11-22 15:35:28 632 [action] Tcp.Client.Connect:test&&192.168.0.4&&50000&&\x0D\x0A&&testEvent

2013-11-22 15:35:28 632 [plugin] TcpMic: TCP.ClientError: System.InvalidOperationException: The stream does not support reading.
Code: [Select]
2013-11-22 15:36:35 712 [action] Tcp.Client.Write:test&&@MAIN:VOL=?\x0D\x0A

2013-11-22 15:36:35 712 [plugin] TcpMic: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
Code: [Select]
2013-11-22 15:35:28 632 [action] Tcp.Client.Write:test&&@MAIN:VOL=?\x0D\x0A

2013-11-22 15:35:28 632 [plugin] TcpMic: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
Code: [Select]
2013-11-22 15:33:11 164 [action] Tcp.Client.Connect:test&&192.168.0.4&&50000&&\x0D\x0A&&testEvent

2013-11-22 15:33:11 164 [plugin] TcpMic: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall. ---> System.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()

The thing you mentioned about possibly getting feedback directly in a call to tcp.single actions sounds nice, hopefully you will get some spare time not to far in the future.[/code]

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin
« Reply #82 on: November 22, 2013, 11:03:17 AM »
Calling connect when you are already connected it may throw an exception but I don't think it matters.  You could try putting a TCP.Client.Disconnect before each TCP.Client.Connect but this is not very elegant.  It might work...

Yes the receiver will disconnect and the TCP libraries in .Net are terrible about not noticing that the connection has been closed by the remote server.  It can take a really long time to notice and may not even notice unless you are sending commands, even when sending command it will put them on a stack or in a buffer or something and act like everything is peachy and still take a while to start throwing errors!  Perhaps when we move to .Net 4 there will be something better we can use.  With my iTach I can open a connection and it stays open reliably unless the network is unplugged or my computer goes to sleep.  When the computer wakes up I do a little thing to reinitialize the connection.

But now that you've got your commands and your terminator done correctly for both sending and receiving you can try the following.

First of all, for just sending commands that don't require feedback, I suggest using TCP.single.  I suspect that this will work reliably, and it is a lot less work for VC, but it might not work all the time if iRule is on and actively trying to keep the connection open.

For commands that require feedback (for now anyway) you have a few options.

Option A.
1 - Create a client using TCP.Client.Connect, send the command(s), don't do anything else in this command
2 - when the feedback event is fired process the feedback from the event payload, and then disconnect the client.

This should all happen almost instantly unless your receiver is very slow to respond for some reason.  The only problem here is that if the event does not come back from some reason the client will remain connected, or at least think that it is...  But you can try it and see if it is reliable now that you are using the terminator correctly.

Option B.
1 - Create a client using TCP.Client.Connect, send the command(s), and then trigger an event by using VC.SetEventTimer.  Use any eventName you want but assign that event to a command that disconnects from the client.  Experiment to see how long the amp takes  to trigger the other event and then try to set the shortest timer delay that will safely let the receiver respond in time.
2 - the feedback event will fire as above but you don't disconnect the client here
3 - the disconnect event will fire next and you can disconnect the client in the command that is triggered.

This should probably work reliably (as long as irule doesn't interfere) but be careful if you have multiple commands going simultaneously that they don't overrun each other where one tries to connect before the other closes (well maybe it will still work...)

Option C. is basically what you were doing before but with the connect terminators and a few minor adjustments.
1 - open the client, send the commands, pause (only for a short time), then disconnect.

This might not work because VC.Pause blocks the main thread of VC and may prevent the TCP stuff from executing.  Try it and if it doesn't work change the name of the command so that it starts with ++  This is a trick to run the command in it's own thread.  Each of the actions in the command will actually be executed on the main thread, but not the containing macro or the VC.Pause actions.  Other actions will be "invoked" or "injected" into the main thread... blech... threading...  Anyway, it can be very helpful sometimes but only use the ++ trick when you need it!

Finally, if it turns out that all this works well but only when iRule is NOT running, and iRule starts to interfere then you have to find another solution and you can't blame the problem on VC.  If your VC machine is on all the time, then you could probably set it up to relay command from iRule to the receiver without toooooo much trouble ;)
« Last Edit: November 22, 2013, 11:12:38 AM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin
« Reply #83 on: November 22, 2013, 11:13:27 AM »
I edited my last post a few times so don't just read the version that you got in your email notification... read the forum version.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin
« Reply #84 on: November 22, 2013, 11:21:49 AM »
I was able to get feedback on all my repetitive executes using this:
I then waited 20min or so and tried again, first I received and exception och the first couple of tries, then I got the feedback RESTRICTED...
Sounds like the receiver is telling you that, so you'll want to read up on what that means.

Scitz0

  • Jr. Member
  • **
  • Posts: 11
  • Karma: 0
    • View Profile
Re: TCP Plugin
« Reply #85 on: November 22, 2013, 11:47:32 AM »
Ok thanks, I will give your different options a try and report back.

Thanks for all the help so far.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin
« Reply #86 on: November 22, 2013, 05:04:53 PM »
You're welcome.  :D

MárlonPrado

  • Jr. Member
  • **
  • Posts: 12
  • Karma: 0
    • View Profile
Re: TCP Plugin
« Reply #87 on: May 16, 2015, 08:55:11 PM »
Hello, good evening.
Excuse my English translation, for I am from Brazil.
I am unable to use the TCP IP plugin.
I need to send an IP address for a server on the LAN, however, in any way I can configure the plugin to control information, ie the IP address has the control information at the end of the address, as being in the following way:
192.168.0.1/t6
Would you like an example of how to configure this IP address in the TCP plugin.
Recalling that need only send this address on the local network as the example above formatted.
Grateful

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: TCP Plugin
« Reply #88 on: May 16, 2015, 09:28:33 PM »
Good evening, Márlon, and welcome to the VoxCommando forum. :)

Please feel free to post your questions in Portuguese. We can use automatic translation tools like Google Translate to translate your questions. But there are also several Portuguese-speaking users who may be able to help you in your native language. This is one reason we invite everyone to post in their own language.

I am not sure I understand your question, but I think you are asking for something like this:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="590" name="change server address to {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="{1} is a &quot;payload&quot;. It will be replaced with the payload that you say in your voice command: &quot;t6&quot; or &quot;t5&quot; or &quot;t4&quot;.">
  <action>
    <cmdType>TCP.Single.Write</cmdType>
    <params>
      <param>your message</param>
      <param>192.168.0.1/{1}</param>
      <param>8080</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>change IP address to</phrase>
  <payloadList>t6,t5,t4</payloadList>
</command>

If you don't know how to use this example in your command tree, please watch this video: http://www.screencast.com/t/0SOZw4TEvq9

 
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin
« Reply #89 on: May 16, 2015, 09:42:25 PM »
I don't think you actually want to use TCP plugin to send messages.  TCP servers do not normally accept any extra information in the address.  So 192.168.0.1/xxx does not make any sense for a TCP message.

It sounds like you want to send a message using "restful" HTTP messages, similar to typing an address into the address bar on your web browser.  If that is the case then you want to use the actions that start with "Scrape" such as "Scrape.Get"

http://voxcommando.com/mediawiki/index.php?title=Actions#Scrape

Maybe you can tell us more about the server that you are trying to communicate with so that we can give you better advice.

Feel free respond in Portuguese. :)