Random data sent TCP - IP:Port

Here is what I am trying to solve:
There is an external application that resides on another networked device that sends out data to an TCP IP:PORT. This is a random event and the end device does not participate as a Server or Listener it simply sends out data to TCP IP:PORT.

If this were a micro-controller I would create an interrupt that functioned when TCP IP:PORT had data. I have read through the most recent MonkeyBread (171) network-socket-method area and do not find what I need or at least do not understand how to implement

I have also attempted to use the Listener or Server examples and both fail since the other side is random.

I can get these to work as they are written by placing one on a desktop and one on another networked device provided the Server Side is started before the Listener side. However in this need the transmitting device never opens a socket until it needs to. That means a Listener will always ERROR out. Using a timer to rebuild the socket has a delay which increases the chances of losing data and once the data is sent there is no resend capability or the ability to request sending data. Basically the end device sending data is looking for a data logger device on the network identified by TCP IP:PORT

So how to implement Listening on a TCP IP:PORT that is not opened by the other end without creating an error on the ‘Listener’ side is what needs to be figured out.

Any thoughts on how to accomplish?


I’m not sure exactly what is going on in your situation, but it sounds like it’s a UDP style of communication over TCP. Normally with TCP there is a handshake that sets up a communication channel between the endpoints. This is what the listening socket is waiting for. Once that is setup you can read any data coming in with the socket’s data available event.

With UDP there is no connection, you just send packets and listen for packets and if they get lost in between it’s up to the application to deal with that.

If your remote application is actually following standard TCP connection mechanisms, you should be able to simply drag a tcpsocket onto a window, set the port, and put some code in the data available event to capture any data that comes in. You will need to tell it to listen when the window opens so it can be waiting for a connection.

Without knowing more about the specifics it’s hard to say exactly what the problem is, but in cases like this, wireshark is your friend. If the sending device is as simple as it sounds, it might not be possible to do what you need in pure Xojo. It might require some low level socket code in a command line tool or plugin that will allow you to capture raw packets on a particular port and process them manually.