Possible to make a TCP socket not bound to port?
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)
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
I think I should put this more simply. I am using Rama'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 Rama'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 Rama's script to read packets the other software is sending?
The BoundToAddress, BoundToEndpoint and BoundToPort methods on FTcpSocketBuilder are optional. You would normally only use these for server (aka. listen) sockets. For client sockets, you can then later use FSocket::Connect to connect to a remote server with a specific IP/port.
If you create a server socket, then yes, it needs to be bound to a local IP/port, otherwise it wouldn't know what to listen to. However, there you can also postpone the binding by calling FSocket::Bind at a later time.
Here's an example:
Take a look at the FTcpSocketBuilder implementation in TcpSocketBuilder.h. It's really just a convenience wrapper around the rather atrocious Socket API.
answered Sep 30 '15 at 05:51 PM
Socket always need port to be defied, there no way around it specially on server which needs static port for client to know where to connect (if you don't define port in client or don't let even specify, client use default one, for example HTTP use port 80, if you don't define port in browser it connects to 80). In case of client socket, port number usually does not matter, so software pick next free one from some specified pool of ports, UE4 seems to have a function for that:
Server knows which client port sending packets, since packets have source port information in them and API usally let you get that information. In case of TCP you just esablish connection from one ip/port to another once and you just reuse that connection, TCP APIs usally work around connection session, insted of signing destination on each of packets (but looking on UE4 APIs that might not be the case :p). If FSocket you got RecvFrom:
Whcih give you address fronm where packet got recived
You seem to making server (listen socket), i'm not sure what software you deal with, but if client can't specify port, it most likely means it's using default port and you need to figure out which one is it (if documentation does not tell use "netstat -o" and "tasklist" to figure pid of client in windows console). If it really asks server for port, it means it's own protocol, because TCP or UDP does not support something like that, it needs specified port so that things also requires port to ask. If you want feather help you need to tell me what are you trying to connect to.
Follow this question
Once you sign in you will be able to subscribe for any updates here