<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Retreive Port Number of UDP Client connected to my UDP Server</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e0203ece43/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e0203ece43/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/e0203ece43/</id><updated>2020-11-24T09:19:45.897000Z</updated><subtitle>Recent posts to Retreive Port Number of UDP Client connected to my UDP Server</subtitle><entry><title>Retreive Port Number of UDP Client connected to my UDP Server</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e0203ece43/?limit=25#74c3" rel="alternate"/><published>2020-11-24T09:19:45.897000Z</published><updated>2020-11-24T09:19:45.897000Z</updated><author><name>appling</name><uri>https://forge.codesys.com/u/appling/</uri></author><id>https://forge.codesys.come43bf18d8b632054d56eb4cfed895a13f2deb547</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi dFx, thank you very much for your reply.&lt;br/&gt;
Yes, in the end I solved it with the NBS library. Their UDP.Receiver has a structure that contains the remote IP and port - that way I could then establish a two way communication. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Retreive Port Number of UDP Client connected to my UDP Server</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e0203ece43/?limit=100#b7c8" rel="alternate"/><published>2020-11-09T21:01:50.014000Z</published><updated>2020-11-09T21:01:50.014000Z</updated><author><name>dFx</name><uri>https://forge.codesys.com/u/dfx/</uri></author><id>https://forge.codesys.com0d56345c96793fc3c856dd87a050eeb1bb337ab6</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Did you had a look at  CAA Net Base Services ?&lt;br/&gt;
&lt;a href="https://help.codesys.com/webapp/idx-CAA_NetBaseServices-lib;product=CAA_NetBaseServices;version=3.5.9.50" rel="nofollow"&gt;https://help.codesys.com/webapp/idx-CAA_NetBaseServices-lib;product=CAA_NetBaseServices;version=3.5.9.50&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Retreive Port Number of UDP Client connected to my UDP Server</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e0203ece43/?limit=25#1d68" rel="alternate"/><published>2020-10-28T09:16:24.293000Z</published><updated>2020-10-28T09:16:24.293000Z</updated><author><name>appling</name><uri>https://forge.codesys.com/u/appling/</uri></author><id>https://forge.codesys.com9120e9adc269ab1ef9e2b7dedab2d6c1fb7e92d4</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello everyone,&lt;/p&gt;
&lt;p&gt;so I am trying to implement a UDP server that will wait for a message from a client and then send data to that client.&lt;br/&gt;
The problem is, I cannot find a way to get the port number of the UDP client that is sending a message to me.&lt;br/&gt;
I have created the socket like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;        &lt;span class="nv"&gt;thesocket&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;SysSockCreate&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;  &lt;span class="nv"&gt;iAddressFamily&lt;/span&gt;  :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;SOCKET_AF_INET&lt;/span&gt;,
                                    &lt;span class="nv"&gt;diType&lt;/span&gt;          :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;SOCKET_DGRAM&lt;/span&gt;,        &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;For&lt;/span&gt; &lt;span class="nv"&gt;UDP&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
                                    &lt;span class="nv"&gt;diProtocol&lt;/span&gt;      :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;SOCKET_IPPROTO_UDP&lt;/span&gt;,  &lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;or&lt;/span&gt; &lt;span class="nv"&gt;SOCKET_IPPROTO_IP&lt;/span&gt; ?
                                    &lt;span class="nv"&gt;pResult&lt;/span&gt;         :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;ADR&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;CreateErrorCode&lt;/span&gt;&lt;span class="ss"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;bound like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;m_bound&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SysSockBind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;         &lt;span class="n"&gt;hSocket&lt;/span&gt;         &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;thesocket&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                &lt;span class="n"&gt;pSockAddr&lt;/span&gt;       &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MySocket&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;   
                                &lt;span class="n"&gt;diSockAddrSize&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SIZEOF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MySocket&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;       
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now I imagine I receive a message here:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;m_receivedBytes&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SysSockRecvFromUdp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;  &lt;span class="n"&gt;hSocketUDP&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;thesocket&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                                        &lt;span class="n"&gt;pbyData&lt;/span&gt;     &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m_RecvBufferAddr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                                        &lt;span class="n"&gt;diDataSize&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m_RecvBufferSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                                        &lt;span class="n"&gt;pReply&lt;/span&gt;      &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m_clientInfo&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
                                        &lt;span class="n"&gt;pResult&lt;/span&gt;     &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m_received&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;now m_clientInfo is of type UDP_REPLY which contains the IP address of the client. When I want to respond via  SysSockSendToUdp I need to specify the destination port (of course).&lt;br/&gt;
In the documentation of sysScoket ( &lt;a href="https://help.codesys.com/webapp/idx-SysSocket%20Implementation-lib;product=SysSocket%20Implementation;version=3.5.15.0" rel="nofollow"&gt;https://help.codesys.com/webapp/idx-SysSocket%20Implementation-lib;product=SysSocket%20Implementation;version=3.5.15.0&lt;/a&gt; ) I could not find a receive method that would work on my UDP socket and give me a socketaddr type.&lt;/p&gt;
&lt;p&gt;I hope someone can help me.&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>