From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Mon, 1 Dec 2008 14:24:27 -0500 From: Ishwar Rattan To: 9fans@9fans.net Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: [9fans] UDP insight needed.. Topicbox-Message-UUID: 55375b22-ead4-11e9-9d60-3106f5b1d025 Trying to get UDP working with announce.dial and friends. Code for an attempted UDP server/client listed below. The server does not get beyond the read() call -- as if the client never got connected. Dial() in client does not return error. Any pointers will bve appreciated. -ishwar -------server.c--- /* Example of a server, echoes back the * info received from a client * It does not complete the read().. */ #include #include #include void main(void) { int afd, lcfd; char adir[40], ldir[40]; int i, n; char buf[256]; afd = announce("udp!*!8001", adir); if(afd < 0) sysfatal("announce..\n"); if(fprint(afd, "headers") < 0) fprint(2, "headers..\n"); sprint(ldir, "%s/data", adir); lcfd = open(ldir, ORDWR); if(lcfd < 0) { close(afd); sysfatal("listen..\n"); } n = read(lcfd, buf, 256); if(n <=0) { close(afd); close(lcfd); sysfatal("read..\n"); } for(i = 0; i < 12; i++) print("%x ", (uchar *)(buf+i)); print("\n"); close(afd); close(lcfd); exits(nil); } --------client.c--- /* Client code for echo client.. */ #include #include void main(void) { char buf[128], *string = "Message to server."; int fd, len; if((fd = dial("udp!localhost!8001", 0, 0, 0)) < 0) sysfatal("dial"); print("after dial..\n"); srand((long)i); sprint(buf, "%s%d", string, rand()); len = strlen(buf) + 1; if(write(fd, buf, len) != len) { close(fd); sysfatal("write..\n"); } buf[0] = 0; read(fd, buf, 128); close(fd); exits(nil); } --------