From: "Daniel P. Zepeda" Date: 2002-01-11T17:06:04+09:00 Subject: Re: Something ODD with UDPSocket - Five second wait? Hello, On Fri, 11 Jan 2002 07:13:11 +0900 "Ralph Mason" wrote: > Here is an odd thing, so odd that I am sure it must be something I am doing > wrong. > > I am using UDP to debug a remote application. So I think, couple of lines > of ruby and I have my tracer. But I run into a problem, it takes about 5 > seconds from when I send the data (from C) for it to be printed by ruby. > This does not happen if I send it from ruby - how odd. I don't know enough about Ruby's UDPSocket internals, but "I get an X second wait" man times flags a DNS lookup timeout or similar situation. Does UDPSocket try to reverse-map addresses or something? > > ---------------------------------------- > > require "socket" > > sock = UDPSocket.open > sock.bind("",2600) > > while true > p sock.recvfrom(512) > end > > ---------------------------------------- > > So far so good, all works fine. > > I test it with some more ruby, and the data is printed instantly > > ---------------------------------------- > > require "socket" > > UDPSocket.open.send("Test debug",0,'localhost',2600) > > ---------------------------------------- > > Works fine. So I start sending to it from C, and it takes 5 seconds for > the data to appear!! > > I cant figure this out. Here is the C I am using to send to the ruby > tracer. > > ---------------------------------------- > int main(int argc, char* argv[]) > { > WSADATA wsaData; > WSAStartup( MAKEWORD( 1,1 ), &wsaData ); > > const char* buff="Testing 1..2..3"; > > SOCKET s=socket(AF_INET,SOCK_DGRAM,0); > > sockaddr_in addr; > memset(&addr,0,sizeof(addr)); > > addr.sin_family = AF_INET; > addr.sin_port=htons(2600); > addr.sin_addr.S_un.S_addr=inet_addr("192.168.1.1"); > > sendto(s,(char*)buff,strlen(buff),0,(sockaddr *)&addr,sizeof(addr)); > > return 0; > } > ---------------------------------------- > > So I think, perhaps it's somethign to do with my machine. and write the a C > tracer program. This one works as I expected the ruby app to work. (and > also goes to show why I wanted to write it in ruby :-) > > ---------------------------------------- > > int main(int argc, char* argv[]) > { > WSADATA wsaData; > WSAStartup( MAKEWORD( 1,1 ), &wsaData ); > > SOCKET s=socket(AF_INET,SOCK_DGRAM,0); > > sockaddr_in addr; > memset(&addr,0,sizeof(addr)); > > addr.sin_family = AF_INET; > addr.sin_port=htons(2600); > addr.sin_addr.S_un.S_addr=INADDR_ANY; > > if ( bind(s,(sockaddr*)&addr,sizeof(addr)) == 0 ) > while(1) > { > char buff[512]; ; > > int i= recvfrom(s,buff,512,0,NULL,NULL); > > if ( i == SOCKET_ERROR ) > { > printf("Error in recvfrom %d\n",WSAGetLastError()); > break; > } > > buff[i]=0; > printf("%s\n",buff); > } > else > puts("Failed to bind"); > > return 0; > } > ---------------------------------------- > > Can anyone help with this? Has anyone seen this problem before? > > > Thanks > Ralph > > > -- Daniel P. Zepeda daniel@zepeda-zone.net