[ back to toc ]

C network programming

Date: 2002/03/31 18:49

Q:
How can i get a client to check for messages from a server and be able to
send messages from a user to the server at the same time.

I'm a newbie to the C language. All i can think of it trying to use fork()
but i'm not sure if this is right or of the syntax for it.

The enviro is Linux using sockets
A:
I assume that 'message' you mean eMail and the protocols are the standard
Internet protocols, namely POP3 and SMTP.

The program should implement the POP3 protocol and the SMTP protocol. To
do that you have to consult the appropriate RFC definitions of the
protocols, or find some open source code that does that. I have done that
once in Perl, which is almost the same regarding sockets. If you need I
can send you the Perl code, to learn from.

To do the sending and the receiving you can do three things:

1. Use fork() and have two processes, one sending and one receiving.

2. Use posix thread functions and start two threads, one sending using
SMTP while the other receiving using POP3.

3. Use only a single thread and use nonblocking socket programming and use
the function 'select' to know if the reading or the sending socket is
ready for the next chunk of transfer.

Visit the site:

http://www.ecst.csuchico.edu/~beej/guide/net/

to see a very good socket programming tutorial. The only weakness of that
tutorial is Windows NT socket programming. But this is not interesting for
you.

Regards,
Peter

[ back to toc ]