Hi

I'm trying to make a little FTP server, but could someone show a small example on how to 'accept' an incoming request (like someone is trying to connect)

I tried the small webserver and some chat progs, but it just won't work

It looks very simple, so i guess I just have a small error somewhere, so if anyone can show me a small example that should work plz :)

Tnx in advance
Posted on 2001-11-24 18:10:53 by Unregistered2
Leaving out the synchronisation stuff, this is how it works:

1. Create a socket (function 'socket'), this is the server socket
2. Bind it with 'bind' to a certain IP (or NULL for all network adapters), and port. (IP and port are in network byte order, i.e. big endian)
3. Set it listening with 'listen'
4. Accept the connection with 'accept' on the server socket. The return value is a new socket (the client socket). You use this socket to send & receive data to and from the client.
5. finally, closesocket for all sockets

Then you'll need the synchronisation, i.e. you'll have to wait for an incomming connection. You can call accept without waiting, but your program will hang until it has accepted an connection then, unless you place this code in a seperate thread.. There are server ways of waiting for specific events.. Have a look at this thread:
http://www.asmcommunity.net/board/index.php?topic=1874
I posted some examples of several methods of writing servers & clients.. They are very ugly examples as they weren't meant to be examples, but simple best speed tests. On page 2 on that thread is another program called server2.

Thomas
Posted on 2001-11-25 04:27:18 by Thomas
Thanks, I will try! :)
Posted on 2001-11-25 10:01:57 by Unregistered2