Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  
Evil Steve


Yay, my socket classes are done. Hooray for multithreading. There's 4 main classes in it:
CSocket represents an actual socket, which you can connet with, send data to, and get it's buffer.
CSocketSet is a class that contains a group of CSockets. You can poll it every loop to get a list of sockets that have new data.
CSocketManager doesn't do much. It has functions for allocating and freeing a socket, and a way to map a SOCKET to a CSocket*.
CSocketServer is used for handling incomming connections. It can listen on several ports at once, and can be polled to see if there's a new connection.

Here's some example code (my test code). It listens for connections on port 23, and prints any data recieved to the console. When once socket becomes invalid (the client disconnected), it breaks out of the loop and cleans up.

#include "Socket.h"

int main(int argc, char** argv)
CSocketServer theServer;
CSocketSet theSet;
std::vector vSocks;
bool bBreak=false;
BYTE byBuff[256];

// Listen on port 23 //
return -1;

// Loop //
// Accept new connections //
CSocket* pSock = theServer.GetNextConnection();

// Process pending //
do {
// Get next socket with data waiting //
pSock = theSet.GetNextPending();

// Is socket valid? //
bBreak = true;

// Process buffer //
size_t nLen = pSock->ExtractBuffer(byBuff,255);
byBuff[nLen] = 0;
} while(pSock);

// Cleanup sockets //
for(DWORD i=0; i CSocketManager::Get().FreeSocket(vSocks);

return 1;

I still need to profile it, I'm a bit worried that there might be some overhead of getting data from the reading threads into the actual socket buffers, but I don't think it'll be too bad.

And I still haven't finished bomberman. There's not much left to do at all, but I went out on Wednesday and spent most of Thursday recovering (Damn you GBP1/drink...). And now I have to go out to a friends birthday, so I doubt I'll be able to do any coding when I come in.
Sign in to follow this  


Recommended Comments

So will Bomberman use this socket crap for two-player multiplayer? Remember the lesson of Muffins.

Share this comment

Link to comment
There will be no 2-player bomberman in the imediate future. Unless I come back to in later on of course. This socket crap is for my MUD.

Share this comment

Link to comment
Why do you neglect the lesson of Muffins? Without multiplayer, crappy AI will be what your game is known for!!


Share this comment

Link to comment

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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!