9fans archive / 1998 / 10 / 6 /    prev next

From: Franklin Robert Araujo França 973930@dcc...
Subject: [9fans] Communication using TCP
Date: Fri, 02 Oct 1998 09:17:17 -0300

    First I´d like to thank Forsyth for answering my CPU server question. Now,
it´s works and I understood how to use the cpu command.

    I wrote two programs for communication between two Plan 9 terminals.

send.c
/* This program sends a string message to a Plan 9 terminal and receives a null
message*/
ctl=dial("il!mercurio!143", 0, devdir, 0);
strcpy(buf1, "Envio de mensagem");
for(i=0; i<10000;i++){
    n=write(ctl, buf1, strlen(buf1));
    n=read(ctl, buf2, sizeof(buf2));
}



receive.c
/*This program receives a string message e sends a null message */
afd=announce("il!mercurio!143", adir);
lcfd=listen(adir, ldir);
dfd=accept(lcfd, ldir);
while(n=read(dfd, buf, sizeof(buf)) > 0){
   empty_message();
   strcpy(buf, "");
   write(dfd, buf, strlen(buf));
}

int empty_message(void){
   return 1;
}

    These programs work correctly using IL, but when I change the protocol to
TCP, these programs don´t work. The send.c program sends a message, then the
receive.c receives the message and sends another. Then, the send.c is blocked.
Why?

    To change the protocol to TCP, I simply change the following:

send.c

dial("tcp!mercurio!143", 0, devdir, 0);

receive.c

announce("tcp!mercurio!143", adir);

    The other question is why I have to use the 143 port? I try to use other
ports, but the programs only work at 143 port.

    Thanks.

Franklin.