09-08-2012, 11:07 AM
For non-Blocking Sockets its easy:
Create a Function That will apply the nonblocking to the sochet:
// where iMode =1 enable nonblocking, iMode = 0 Disable nonblocong
int applyNonBlocking(int Socket,int iMode){
int result = -1; //Socket_error
#ifdef WIN32
u_long opt = (u_long)iMode;
//activate nonblocking sockets
result = ioctlsocket(Socket,FIONBIO, &opt);
#else
//activate nonblocking sockets
result = ioctl(Socket, FIONBIO, &iMode);
#endif
return result;
}
Then after Accepting a client you can apply nonblocking sockets:
// new socket for every client,
// you could create a socket wheel using a for loop to handle many clients
int clientSocket;
clientSocket = accept(Socket, 0, 0);
//apply nonBlocking to the client sockets
applyNonBlocking(clientSocket, 1);
// the server accepting clients will be blocked(unless you want to applynonBlocking to Socket),
// but the communication client/server will ne nonBlocked
If you want nonBlocing on the client you can simply Apply Apply socket after you created a socket.[/code]
For async usually is Win32 programming.
To create an worker sockets it will require to know threads, there are 3 ways to create a thread:
1) by using windows threads(limited to windows)
2) By using POSIX threads(which is not limited to OS)
3)You can use MPI(Mwssage Passing Interface).
I'll post a separate tutorial in Pthreads, and windows Threads, to not make it make this thred too complex.

