# Problem with server/client

This topic is 4186 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Quote:
 Original post by CrazyfoolOk, 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 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 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 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 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 on other sites

This should be all you need:

#include <winsock2.h>#include <windows.h>#pragma comment(lib, "ws2_32.lib") 
 0 
 Share this post Link to post Share on other sites 
 
 
 Crazyfool    307 Crazyfool    307 Contributor Member 307 1230 posts Joined August 2006 Posted September 7, 2006 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 externalsError executing link.exe.Yes, I named it HelloWorld ;D 0 Share this post Link to post Share on other sites 
 Sign in to follow this   Followers 0 
 Go To Topic Listing Networking and Multiplayer Advertisement 
 Advertisement Popular Tags 2D 3D Advice Algorithm C# C++ Character Concept Design DX11 Feedback GameMaker Gameplay General Java Learning Mobile Music OpenGL PC Pixel Python Unity Unreal VR Advertisement Popular Now 10 Upvoting and Downvoting By francoisdiy Started 18 hours ago 14 Breaking into the Industry with a Bad Degree - Can it be Done? By rcrawford115 Started Tuesday at 03:57 PM 11 The fun of the last part of playing RTS By Pleistorm Started Tuesday at 01:12 PM 10 DX11 Duplicate Vertices using std::map By isu diss Started Tuesday at 08:11 AM 11 Need to map Xbox360 controller. By Timothy Sharp Started Tuesday at 12:31 AM Advertisement GDNet Discord Chat All Activity Home Forums Programming Networking and Multiplayer Problem with server/client