Valhalla Legends Forums Archive | Battle.net Bot Development | sockets (C++)

AuthorMessageTime
K
Hullo. I'm currently working on a (chat)bot in C++. While my current code works, I'm getting the feeling that there's a better way this could be done, so I was looking for suggestions (not code, preferably). What I'm doing as of now is creating a seperate thread that polls the socket for data / the queue for outbound messages and if either are found processes them, and if not sleeps for a specified amount of time. This seems like a really poor idea to me as a programmer, so I was looking for alternatives.

TIA,
/K

[Edit: just read through the thread titled "BNCS Chatgate Event Handler" and found a good starting point. Suggestions still welcome, though.]
April 5, 2003, 4:14 PM
Kp
What operating system are you designing for? The efficient methods for Win32 and *nix are extremely different. Specifically, the win32 one is win32-specific (surprise!) and the *nix one works very poorly under Win32.
April 5, 2003, 5:44 PM
K
Sorry, should have specified Win32. I've been looking at WSARecv and WSASend, but I'm not sure I understand exactly what the benefit of the callback function is.
April 5, 2003, 7:53 PM
Zakath
There's absolutely no need for a separate thread simply for socket processing: consider BinaryChat, which can use a dynamic number of Battle.net connections, and does ALL the GUI and socket handling in one thread.

The easiest way, in Windows GUI programming, is probably to use WSAAsyncSelect()...look it up in the MSDN.
April 5, 2003, 8:43 PM
K
Thanks Zakath, I had come to that conclusion which is why I posted my question here. I was looking at WSAAsyncSelect(), but in the thread I referenced, Skywing recommended against using it. Thanks for your reply.
April 5, 2003, 9:04 PM
Skywing
[quote author=K link=board=17;threadid=955;start=0#msg7123 date=1049572423]
Sorry, should have specified Win32. I've been looking at WSARecv and WSASend, but I'm not sure I understand exactly what the benefit of the callback function is.
[/quote]Overlapped operations allow you to guarantee to the system that a buffer will remain valid for the entire operation, which in turn allows the system to take signifigant optimizations (such as not having to copy data to and from internal buffers).

Additionally, overlapped operations typically execute through the system's dedicated I/O worker thread system, with completion notifications being posted to the thread which issued the overlapped request. The system directs a thread to execute all pending asynchronous procedure calls (APCs) - such as a pending overlapped completion notification function call - whenever it enters an alertable wait state (see SleepEx, SignalObjectAndWait, WaitForSingleObjectEx, WaitForMultipleObjectsEx, MsgWaitForMultipleObjectsEx, and WSAWaitForMultipleEvents).

On a side note, using overlapped sockets operations is a great way to remove the "64 socket limitation" (the wait functions can only wait on up to 64 objects).
April 5, 2003, 9:13 PM

Search