9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Communication using TCP
@ 1998-10-02 12:17 Franklin
  0 siblings, 0 replies; 2+ messages in thread
From: Franklin @ 1998-10-02 12:17 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 1427 bytes --]

    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.






^ permalink raw reply	[flat|nested] 2+ messages in thread

* [9fans] Communication using TCP
@ 1998-10-02 15:20 Russ
  0 siblings, 0 replies; 2+ messages in thread
From: Russ @ 1998-10-02 15:20 UTC (permalink / raw)


IL preserves message boundaries, while TCP
does not.  So if you write a 0 byte message
over IL, then a 0 byte message goes across the wire.
If you write a 0 byte message over TCP, then
0 bytes (nothing) goes across the wire.

In a very simplified mental model, think of IL
as sending length<msg>, while TCP just sends msg.
So a 0 byte write in IL sends
	0<>
while TCP sends 

(nothing), so the other end doesn't know that you've
actually done the write.  

As for why you can only use 143, I'll bet most ports
work, but the ports you tried were already being 
handled by aux/listen.  Look in /bin/service/ to
see what ports are already in use.

Russ




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-10-02 15:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-02 12:17 [9fans] Communication using TCP Franklin
1998-10-02 15:20 Russ

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).