UDP connection -> outgoing port trouble (still)
-
Good morning, last week I already wrote about my little problem. Then I got sick and and couldn´t take part in the conversation. Even though I got an answer it didn´t help (or I misunderstood). Now I wanted to ask/clarify and would be glad for some help. The code:
SOCKET m_oUDPSocket;
SOCKADDR_IN m_oUDPAddress;.
.
.m_oUDPSocket = socket(AF_INET,SOCK_DGRAM,0);
memset(&m_oUDPAddress,0,sizeof(SOCKADDR_IN));
m_oUDPAddress.sin_family=AF_INET;
m_oUDPAddress.sin_port=htons(m_iClientPort);
m_oUDPAddress.sin_addr.s_addr=inet_addr(m_sClientIP.data());.
.
.int rc=sendto(m_oUDPSocket,(char*)packet,size+12,0,(SOCKADDR*)&m_oUDPAddress,sizeof(SOCKADDR_IN));
The problem: I´d like to send the data via 'sendto' ALWAYS on the same outgoing port. The question: Where and how do I define this outgoing port? Do I have to create another SOCKADDR_IN with the server port and address and bind it to m_oUDPSocket? Like this?
SOCKADDR_IN addr;
memset(&addr,0,sizeof(SOCKADDR_IN));
addr.sin_family=AF_INET;
addr.sin_port=htons(desiredPort);
addr.sin_addr.s_addr=INADDR_ANY;
rc=bind(m_oUDPSocket,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN));Or am I on the wrong path here? And how can I test if it indeed sends from the desired port? Thanks for any help. Souldrift
-
Good morning, last week I already wrote about my little problem. Then I got sick and and couldn´t take part in the conversation. Even though I got an answer it didn´t help (or I misunderstood). Now I wanted to ask/clarify and would be glad for some help. The code:
SOCKET m_oUDPSocket;
SOCKADDR_IN m_oUDPAddress;.
.
.m_oUDPSocket = socket(AF_INET,SOCK_DGRAM,0);
memset(&m_oUDPAddress,0,sizeof(SOCKADDR_IN));
m_oUDPAddress.sin_family=AF_INET;
m_oUDPAddress.sin_port=htons(m_iClientPort);
m_oUDPAddress.sin_addr.s_addr=inet_addr(m_sClientIP.data());.
.
.int rc=sendto(m_oUDPSocket,(char*)packet,size+12,0,(SOCKADDR*)&m_oUDPAddress,sizeof(SOCKADDR_IN));
The problem: I´d like to send the data via 'sendto' ALWAYS on the same outgoing port. The question: Where and how do I define this outgoing port? Do I have to create another SOCKADDR_IN with the server port and address and bind it to m_oUDPSocket? Like this?
SOCKADDR_IN addr;
memset(&addr,0,sizeof(SOCKADDR_IN));
addr.sin_family=AF_INET;
addr.sin_port=htons(desiredPort);
addr.sin_addr.s_addr=INADDR_ANY;
rc=bind(m_oUDPSocket,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN));Or am I on the wrong path here? And how can I test if it indeed sends from the desired port? Thanks for any help. Souldrift
-
What do u mean by outgoing port? Normally the ipaddr and the port number on which u need to send the data will be fixed. client must have the PortNo and Ipaddr to send the data in UDP to server.
-
Well, by outgoing port I mean simply the UDP port. The question was, how do I get a fixed one? By now I figured that it is the 'bind' command that will do that. Though, what UDP port does the server use if I do NOT specify a bind? Regards Souldrift