I’ve found a C++ script that receives TCP packets on a certain port, utilizing Unreal’s FTcpSocketBuilder functionality.
It needs to know the local port to be specified, since it requires a local endpoint to be bound to (or at least it seems so, since I couldn’t get it to work otherwise, might just be that I’m a noob). (see code)
//makes an endpoint defined by the machine's ip and a specific port
FIPv4Endpoint Endpoint(clientIP, clientPort);
//makes a listensocket bound to that endpoint
FSocket* ListenSocket = FTcpSocketBuilder(*YourChosenSocketName)
.AsReusable()
.BoundToEndpoint(Endpoint)
.Listening(8);
When the software that I’m streaming the TCP packets from allows me to specify the client’s port, it’s all ok.
However, the software I am using can’t do that. It uses the apparently common approach of asking the client for a port first (which the client designates from a pool of so-called ephemeral ports), and streaming to that port. That means that the client port is different every time a new stream starts, and the thing that’s fixed is the server’s port.
My question is - is there a way for Unreal to identify which port the stream is taking place at (since I know the source ip, source port and destination ip)? In other words, does the TCP socket have to be bound to a pre-defined port?
An alternative solution (which would probably be considered off-topic in an Unreal answer hub) would involve some way of specifying a fixed port for the packets to be sent to on the server side. I assume it can be done by
- tricking the streamer software into
believing the client returned a
certain port as an available
ephemeral one - re-routing all packets it sends to
any port of a certain ip to a
specified port (this, however,
involves a risk or accidentally
including some packet headed to that
ip that wasn’t part of the stream) - any other viable option that I might
not think of since I am very
inexperienced with all of this
Cheers
EDIT:
I think I should put this more simply. I am using 's script and have no idea why it’s so long and convoluted. I read through it and grasped the general concepts as well as the flow of logic, but I don’t have any idea how some of those functions work, what to modify there and why specifically. I should’ve started with saying I have very little experience with C++ and TCP in general.
So, I’ve implemented 's script, so everything works when I sent packets from this software (that I use for testing only), and as you can see I can specify receiving port as proven by a wireshark capture.
However it doesn’t work when I send them from this other software (which I intend to use in the final setup), which specifies the sending port, as you can see from the second wireshark capture, since the receiving port for that stream is different every time (but the sending one is always the same).
How do I make it possible for 's script to read packets the other software is sending?