Sign in to follow this  
Crazyfool

Problem with server/client

Recommended Posts

Ok, so I got a blocking server/client to connect, but thats not my goal. I want to make a server that allows for multiple connections, and for it to be consntantly listening to add connections. Not only that, I want it to be constantly checking for packets of data sent to it, and for it to be able to send packets while still listening to incoming connections. I have looked around and found that asynchernomous(sp) and multithreaded servers are the solution, but I have looked around and all of them do things I do not need, or do not explain completely. Some use MFC, which I would not like to use (unless I am misunderstanding and I NEED it) or dont explain at all, and their code is very hard for me to understand. Simply using a code and then just adding bits is fine, but I want to understand how things work. So I am asking for anything to direct me to a good place to learn about it; WS Programmer's FAQ hasnt helped much, nore has the MSDN, nor any of the guides I looked through. I am terribly sorry if I seem like I am a newbie unwilling to search, but I have searched. Perhaps for some quite experienced, you could write a tutorial since it seems a lot of the tutorials aren't quite so friendly in terms of explaining. [Edited by - Crazyfool on September 7, 2006 12:28:07 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Crazyfool
Ok, so I got a blocking server/client to connect, but thats not my goal.

I want to make a server that allows for multiple connections, and for it to be consntantly listening to add connections. Not only that, I want it to be constantly checking for packets of data sent to it, and for it to be able to send packets while still listening to incoming connections.

I have looked around and found that asynchernomous(sp) and multithreaded servers are the solution, but I have looked around and all of them do things I do not need, or do not explain completely.


They're one solution. select() or poll() are another category of solutions, which work fine for smaller servers. You can call select() every few milliseconds to see which sockets have some data, and then handle them individually.

Share this post


Link to post
Share on other sites
There are several resources pointed at from the Forum FAQ. For example, check out the Etwork sample code.

In general, the best way to go about this in the beginning is to stuff all the sockets into a call to select(), and then service the sockets that return ready. If a listening socket returns ready, it means you can accept() on it without blocking; if a connected socket returns ready, it means you can recv() (or send()) on it without blocking.

Once you start getting into hundreds of connections, you may need to move to a solution using IOCP on Windows (check MSDN for CreateCompletionPort()), but don't worry about that right now.

Share this post


Link to post
Share on other sites
Ah, I'll definately look into that. However, would you say you'd probably use multithreading? I know whatever works is the best choice, but I dont like limiting the amount to a "small server" even though that it is probably what it will ever be. Anyway, thanks much, I'll dive into that.

Share this post


Link to post
Share on other sites
Quote:
would you say you'd probably use multithreading?


We run server clusters with thousands of users, based entirely on select() (although on UNIX, where it scales better than on Windows).

If I were to serve more than 60 TCP users on Windows, I might consider going to the IOCP model, which is _a_ form of multi-threading, but is not what you traditionally mean by "multi-threaded sockets." IOCP is very specific to how the Windows kernel works.

I would never try a model like "one thread per socket" or even "one thread per N sockets." Control belongs in the main thread, and completion service gets farmed out to worker threads, which should be no more than one per physical CPU.

Share this post


Link to post
Share on other sites
Er, got pretty lost with your last little go; I read that UNIX can do select() far better than windows, so Yea.

Anyway, the examples on the Winsock Programmer's FAQ never work for me, but I get lots and lots of link errors. I include the appropriate libaries in the Project>Settings>Link, and I made sure to download the sources they use as well, and still have problems.

Theyre using winsock1. I looked into the etwork, and dont understand it completely, but I havent had much time to dissect it.

Argh, frusteration! I am sorry if I have the answers right infront of me and cant see it.

Share this post


Link to post
Share on other sites
I appreciate your patience, and here are the 3 errors I get after changing things around:

Linking...
Hello World.obj : error LNK2001: unresolved external symbol "char const * __cdecl WSAGetLastErrorMessage(char const *,int)" (?WSAGetLastErrorMessage@@YAPBDPBDH@Z)

Hello World.obj : error LNK2001: unresolved external symbol "bool __cdecl ShutdownConnection(unsigned int)" (?ShutdownConnection@@YA_NI@Z)

Debug/Hello World.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.


Yes, I named it HelloWorld ;D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this