How to detect source IP in DATA_EVENT at server side
MorgoZ
Posts: 116
Hi all,
i need to control a Sony SRG-300H camera. The problem is that this is an IP Camera through UDP, so i had to open a client port to send messages to the camera and open a server port to receive the responses from the camera, as follows:
Everything works fine if i control ONE camera, but if i try to connect to more cameras (two, for example). I can send the messages correctly because with "ip_client" i have to especify the ip of the camera, but at the receive side (server side), because ALL messages from ALL cameras are received at the same port (52381 UDP), i have no way to detect which message is from which camera.
So the question is: Is there a way to detect the source ip of a message received inside a DATA_EVENT of a server port?
Need to implement something like this:
i need to control a Sony SRG-300H camera. The problem is that this is an IP Camera through UDP, so i had to open a client port to send messages to the camera and open a server port to receive the responses from the camera, as follows:
ip_client_open(dvCameraSend.PORT,acIPCam,52381,IP_UDP) //To send messages to the camera . . . DATA_EVENT[0:1:0] { online: { ip_server_open(dvCameraRcv.PORT,52381,IP_UDP) //To receive messages from the camera } }
Everything works fine if i control ONE camera, but if i try to connect to more cameras (two, for example). I can send the messages correctly because with "ip_client" i have to especify the ip of the camera, but at the receive side (server side), because ALL messages from ALL cameras are received at the same port (52381 UDP), i have no way to detect which message is from which camera.
So the question is: Is there a way to detect the source ip of a message received inside a DATA_EVENT of a server port?
Need to implement something like this:
DATA_EVENT[dvCameraRcv] { string: { if(data.source.ip == 192.168.1.100) //do something else if(data.source.ip == 192.168.1.101) //whatever . . . } }
0
Comments
But, if i create one ip port for each server connection, just works the first one created, because Netlinx works as follows, for example:
"link port 20 to UDP port 52381 AND link port 30 to UDP port 52381" -ALL Cameras replies ALLWAYS to por 52381, no way to change it-. So, with that configuration the only port that receives messages in practice is the por 20, at port 30 i receive nothing.
And that is why i think that a solution would be to detect the source IP of the message at port 20.
Thanks.
I don't get why you would need to open a server port to rx from the camera though, it makes no sense. You should just need a Netlinx port/socket per camera like: Open a connection to each camera's IP and the camera should respond to the client's (Netlinx) socket. Netlinx should be able to handle 200 sockets to 200 servers (cameras) on the same server port and obviously different IPs.
the approach that you suggest opening a socket connection for each camera is correct IF the cameras would be TCP cameras, but it doesn´t work with a UDP connection, because UDP is not a connection oriented protocol.
I´ll try to explain how do the cameras manage the communication with a controller.
NETLINX PORT (Logic port) || MASTER SOCKET PORT (Real port) || CAMERA PORT
20
> 2025 (anyone selected by the Master)
> 52381 (listening port)
30 (listening) <
52381 (programatically configured) <
3456 (anyone selected by the camera to answer the Master)
Because it is UDP, the camera hasn´t got to answer the sender through the same port it receives the message (in the example, 2025), and the connection protocol is defined by the manufacturer. In this case, the controller (Master) has to connect to the camera to the 52381 UDP port, and by Sony definition, the camera allways answers the sender to the 52381 port. The problem is that i can´t manage the Master socket ports (i can´t tell the Master to open "real" port 52381 to connect the camera), the "real" ports are manages by the Master and this process is hidden (transparent) to the programmer, so i have to open a server connection appart.
Anyway, thanks for the "SOURCEIP" property. I think this will help
--D