View Single Post
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: UDP-Sockets chat application question

 
0
  #4
Nov 20th, 2008
> i read somewhere that sockets are full duplex, so initially i tried to build an architecture like this:
a socket is *one* end of a two-way communications link.
a BSD socket maintains a separate send buffer and a receive buffer, and is full-duplex (you can both send and receive data on it).
to send or receive data, you need two sockets (one at either end).
in your first example, you are trying to use the *same* socket at both ends.

create *two* sockets, one for the client and another for the server.
(eg. socketpair does this for UNIX sockets. http://www.freebsd.org/cgi/man.cgi?query=socketpair)
after forking, close the client socket in the server, and the server socket in the client.
and things should be ok.
  1. +---------------+ +---------------+
  2. | | | |
  3. | peer1 | | peer2 |
  4. | |port1 port2| |
  5. | sock1----|---------------|----sock2 |
  6. | | | |
  7. | | | |
  8. +---------------+ +---------------+

> Could this diversion be "easily" done, by using ncurses
yes.
Reply With Quote