Hole Punching: How to bind to an OS Port for a TCPSocket connect.

I am exploring TCP hole punching classes for Xojo. Does anyone know how to bind an outgoing TCP connection to a specific OS Port? I think this is similar to the binding that happens on Listen.

In other languages I’ve explored (i.e. GO) there is both and internal port and destination port setting so it seems like it might be fairly straight forward. I need a solution (declares?) for both Mac and Windows OS.

Thanks a bunch,

Keith DeLong

No replies so I thought I’d add some additional info:

I’m working on TCP/SSL Socket hole punching classes. This will allow apps behind a NAT to communicate in the Internet. Think Internet of Things (IOT).

What I need is access to socket functionality not exposed by Xojo. Specifically, I need a Mac & Windows solution where I can:

  1. Set the Internal IP address/Port (in addition to the destination IP/Port provided by Xojo).
  2. Set the SO_REUSEADDR and SO_REUSEPORT properties.

Does anyone have expertise to lend a hand with declares? I’m happy to pay for assistance.

Well, if needed, I could add methods for those to MBS Plugin.

As you see here, I have various Option methods for SocketCore there:
http://www.monkeybreadsoftware.net/pluginpart-network.shtml

and for the UDP Socket I have ReusePort/ReuseAddress already.
Interested?

Hi Christian, Thanks for your willingness to help. I’m absolutely interested. I’ll contact you directly.

I’ll try to add them.

Added :slight_smile:
Plugin available on request.

@Christian - I would like the plugin - thanks

just download 17.2pr3.

or 17.1:
https://www.monkeybreadsoftware.de/xojo/download.shtml

Thanks

Downloaded - cannot find a method or plugin that works.

Here is what I am trying to solve:
There is an external application that sends out data to an 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 ip:port had data. I have read through the network-socket-method area and do not find what I need or at least do not understand how to implement

I have attempted to use a Listener or Server and both fail since the other side is random. Creating a timer means that when the socket errors and a rebuild occurs I can miss the data since data is sent out randomly. There is no ability to request data. The end device simply sends the data when available to TCP ip:port

Any thoughts?

Thanks

I had thought I messed up the Server - Listener. However I made several attempts to change where these apps were and it appears that ‘Listening’ on a TCP Port does not work unless the other side has a socket open on that port

If that is accurate then this situation where an end device sends out data on a TCP ip:port whenever it needs to will not work since the socket is not established until the end device needs it.

There must be a way to do this as this is like a ‘Data Logger’ where data is sent randomly to an IP:Port

I am moving this to its own thread

@Christian Schmitz That was very kind of you. I am looking for exactly that functionality, as I am writing a small tool to simulate the action of a serial device server that sends data from a different port depending on which serial device it’s from.

So should I be looking at:

RAWSocketMBS.Bind(Port as Integer, IP as string = “”)

?

Recht vielen Dank!

Well, first start with a subclass of RAWSocketMBS, so you can fill events.
Make a new object from it.
And then make a new socket and finally bind it to a port.

see example
https://www.monkeybreadsoftware.net/example-network-rawsocket-rawsocketaccept.shtml