9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Ishwar Rattan <ishwar@pali.cps.cmich.edu>
To: 9fans@9fans.net
Subject: [9fans] UDP insight needed..
Date: Mon,  1 Dec 2008 14:24:27 -0500	[thread overview]
Message-ID: <Pine.LNX.4.64.0812011420190.6464@pali.cps.cmich.edu> (raw)


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 <u.h>
#include <libc.h>
#include <ip.h>

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 <u.h>
#include <libc.h>

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);
}
--------




             reply	other threads:[~2008-12-01 19:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-01 19:24 Ishwar Rattan [this message]
2008-12-01 22:20 ` erik quanstrom
2008-12-01 22:53   ` Gabriel Diaz Lopez de la Llave

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0812011420190.6464@pali.cps.cmich.edu \
    --to=ishwar@pali.cps.cmich.edu \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).