problem with the udp socket
- From: Irshad <Irshad@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 14 Nov 2005 07:11:18 -0800
Hi All,
I am facing an issue with the UDP sockets in PPC 2003.
The sockets are created and I am able to bind also both the client and the
server apps to the port and the ethereal shows that data is being transferred
from the client to the server app but after the client sendto() is executed
it generates an ICMP packet which says Destination/Port unreachable and the
recvfrom() on the server end hangs.
I am running the server and the client on two systems connected through the
cross cable. I am posting the code for both the server and the client.
Also the same code runs perfectly fine on the same setup for the desktop. It
does not generate any such ICMP packets for Port unreachable and recvfrom()
also successfully executes. Please help!
//===========Client.cpp===========
char *server_name= "10.112.41.5";
struct sockaddr_in si_other, self;
int s, i, slen=sizeof(si_other);
char buf[256];
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return FALSE;
}
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
{
MessageBox(NULL,L"Error Opening socket" , NULL , 0);
}
memset((char *) &si_other, sizeof(si_other), 0);
si_other.sin_family = AF_INET;
si_other.sin_port = htons(10000);
si_other.sin_addr.s_addr = inet_addr(server_name);
int test2 = 1;
int yy = setsockopt(s, SOL_SOCKET , SO_KEEPALIVE , (char *) &test2 ,
(int)sizeof(test2));
if (bind(s, (struct sockaddr *)&self, sizeof(self)) == -1)
{ MessageBox(NULL,L"error binding\n" , NULL , 0);
}
memset(buf,0,256);
strcpy(buf, "Data sent to the server");
while (1)
{
if (sendto(s, buf, strlen(buf), 0, (struct sockaddr *)&si_other, slen)==-1)
{
MessageBox(NULL,L"sendto failed\n" , NULL , 0);
}
closesocket(s);
return TRUE;
//======================
//=========Server.cpp ==============
struct sockaddr_in si_me, si_other;
int s, i, slen =sizeof(si_other);
char buf[256];
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return FALSE;
}
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
{
MessageBox(NULL,L"Error Opening socket" , NULL , 0);
}
memset((char *) &si_other, sizeof(si_other), 0);
si_other.sin_family = AF_INET;
si_other.sin_port = htons(1080);
si_other.sin_addr.s_addr =INADDR_ANY;
memset(buf,0,256);
int errRecvFrom ;
int test2 = 1;
int yy= setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *) &test2,
(int)sizeof(test2));
int errSetSockOpt = WSAGetLastError();
if (bind(s, (struct sockaddr *)&si_other, sizeof(si_other))==-1)
{
MessageBox(NULL,L"Error binding socket" , NULL , 0);
}
while(1){
if (recvfrom(s, (char *)buf, 23, 0 , (struct sockaddr *)&si_other, &slen)==-1)
{
MessageBox(NULL,L"recvfrom error " , NULL , 0);
}
else
MessageBox(NULL,L"recvfrom success" , NULL , 0);
}
closesocket(s);
return TRUE;
}
.
- Follow-Ups:
- Re: problem with the udp socket
- From: Omar [MS]
- Re: problem with the udp socket
- Prev by Date: Can anyone guide me in implementing Flight-mode for Windows Mobile 5.0
- Next by Date: Re: Post 1000 Message to Newsgroups Promoting my site and earn $100.00
- Previous by thread: Can anyone guide me in implementing Flight-mode for Windows Mobile 5.0
- Next by thread: Re: problem with the udp socket
- Index(es):
Relevant Pages
|