View Single Post
Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Re: UDP-Sockets chat application question

 
0
  #5
Nov 21st, 2008
Thanks for your answers vijayan,

Originally Posted by vijayan121 View Post
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).
nice explanation!

but:
>http://en.wikipedia.org/wiki/Duplex_(telecommunications)

Originally Posted by vijayan121 View Post
in your first example, you are trying to use the *same* socket at both ends.
As far as i can understand full-duplex is called when you can send and receive at the same time. So if a socket is a full duplex communications endpoint then you can send and receive data at the same time {from the same endpoint}. In the first example i wanted to do exactly this thing that is send and listen at the same time. Because these procedures are blocking, i thought that a way to circumvent this behaviour was to create a fork...

Originally Posted by vijayan121 View Post
create *two* sockets, one for the client and another for the server.
but i don't have a client-server scheme but a peer-to-peer scheme. The way i see it each peer must be a client and a server at the same time. Is there any other way to make peer-to-peer conversation? I am asking because it is the first i get exposed to the concept of p2p communication and not client-server

Originally Posted by vijayan121 View Post
(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. +---------------+ +---------------+
I can't use socketpair because according to the man page
This call is currently implemented only for the UNIX domain.
and i want internet domain....

Originally Posted by vijayan121 View Post
> Could this diversion be "easily" done, by using ncurses
yes.
I will try to do it this weekend...

Thanks again for your effort and your time,
Although i have a found a kind of solution to this problem {the one i posted in my second post with the use of 2 sockets per peer}, i keep asking because either i don't understand the concept of a socket, port,etc,... or i am doing something terribly wrong...

with regards,
nicolas

PS: as a side effect question what is the relation between a socket and a port. I mean a socket is a special kind of file descriptor, since when i use file descriptors i don't use ports, why we have to use ports when we use a socket?
Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.

by Robert Frost the "The Road Not Taken"
Reply With Quote