c++ - c# udpClient sent packets don't exist the router -
using following code:
udpclient sender = new udpclient(); try { sender.send(encoding.ascii.getbytes(msgout), msgout.length, ip); }
i trying send reply previous request same ip/port. while working on same computer, work if customize values localhost, not work when state own computer ip in nat.
2 facts it:
1) same ip/port values work fine on c++ version of it. (even across globe) next code:
sockaddr_in si_custom; int s_custom; //create socket if ((s_custom = socket(af_inet, sock_dgram, ipproto_udp)) == socket_error) { //socket fail return false; } //setup address structure memset((char *)&si_custom, 0, sizeof(si_custom)); si_custom.sin_family = af_inet; si_custom.sin_port = htons(stoi(port)); si_custom.sin_addr.s_un.s_addr = inet_addr(ip.c_str()); //send message if (sendto(s, msg.c_str(), msg.size(), 0, (struct sockaddr *) &si_custom, slen) == socket_error) { closesocket(s_custom); return false; } closesocket(s_custom); return true;
2) after enabling close remotely relative in firewall, wireshark packet sniffer tells me packets leave computer normal.
i'm trying figure out, why c# udpclient class behave differently c++ udp code in sense router refuses pass first 1 , agrees pass latter one.
thanks in advance.
initializing udpclient sender object own ip:port solved problem
udpclient sender = new udpclient( new ipendpoint(myip,myport));
Comments
Post a Comment