Hi,

I'm playing around with winsock but having some troubles with WSAASyncSelect.


.data?
hwnd dd ?

.const
WM_SOCKET equ WM_USER+100

.code
[...]
push FD_CONNECT+FD_READ+FD_CLOSE
push WM_SOCKET
push hwnd
push hSocket
call WSAASyncSelect

[...]
WndProc PROC hWnd:DWORD, uMg:DWORD, wParam:DWORD, lParam:DWORD
.if uMsg == WM_SOCKET
.if wParam == FD_CLOSE
; do something
.endif
.endif
WndProc endp


WSAGetLastError returns WSA_INVALID_PARAMETER, though I don't know what parameter is wrong.

I havn't created a window, because I don't want one. Is this the error? How can I recieve messages without a window?

Regards,
n1mda
Posted on 2008-09-22 09:40:22 by n1mda
Dont use WSAAsyncSelect, it demands a window, and it chokes that window's message queue when the network load is high, so the whole GUI locks up on you. Even one socket can lock your GUI when its working hard, thats just not cool.

Use the Select api, or better yet, use WSAWaitForMultipleEvents (up to 64 sockets per thread).

If you need more sockets than that, look at the IOCP model, or use the above with N threads.


Posted on 2008-09-22 11:26:49 by Homer
Or you can use WSAEventSelect, partition all your sockets into MAXIMUM_WAIT_OBJECTS balanced pools, and when WSAWaitForMultipleEvents (or simply WaitForMultipleObjectsEx) triggers, simply iterate through the associated pool and do WSAEnumNetworkEvents to see whether the socket has triggered. This scales a lot better than you might think :)
Posted on 2008-09-22 20:06:52 by f0dder
Thank you for your answers, it's starting to clear up now...

Is WSAEventSelect and WSAWaitForMultipleEvents for Winsock2 only?

Because I've been working with 1.1 so far. What's the main difference between 1.1 and 2.0?

As far as I understand, select() would work for winsock 1.1.

Are there any examples online?
Posted on 2008-09-23 13:41:19 by n1mda
What's the main difference between 1.1 and 2.0?

Well, 2.0 is simply better ^^ It has everything that 1.1 has plus some new things. 2.0 supersedes 1.1, so just switch to it if possible.
Posted on 2008-09-23 17:27:57 by ti_mo_n
Iirc the only version of 32-bit windows that didn't have Winsock 2 was Win95, but you could get an upgrade patch for that... so there's not much reason to stick with 1.x, especially today when Win9x is all but dead :)
Posted on 2008-09-23 17:41:11 by f0dder
forget 2.0 - if you can use 2.0, then you can use 2.2
Posted on 2008-09-24 06:15:41 by Homer
forget 2.0 - if you can use 2.0, then you can use 2.2

Yeah, I meant "the new one" (2.2 IIRC) ^^
Posted on 2008-09-25 11:18:42 by ti_mo_n
2.2 has some really nice stuff added, mostly relating to asychronous operations.
This will be important if you ever wish to write multithreaded network code.
The more you learn, the more there is to learn.
Ironic, yes?
Posted on 2008-09-26 01:57:46 by Homer
All,

So to summarize the answers it is better to use WSAWaitForMultipleEvents with Winsock 2.2 than use WSAASyncSelect with Winsock 1.1? Or the Select() function?

Regards,
Uzarius
Posted on 2008-09-26 08:07:14 by Uzarius
I think everyone will agree that Winsock2.2's functions are better than Winsock1.1's, in general. But if you're asking about specific functions, it mostly depends on what you're trying to make.
Posted on 2008-09-26 09:18:44 by ti_mo_n
You should stay away from WSASyncSelect() unless you're writing software with really low-volume requirements. And heck, even for that, I'd probably still go for WSAEventSelect() :)
Posted on 2008-09-26 11:20:09 by f0dder
That sets it, I'm moving to Winsock2,2.

Though I havn't been able to find any examples online with a working WSAWaitForMultipleEvents. Any suggestions?

Thank you a lot for your help guys, dilirious!
Posted on 2008-09-26 11:20:36 by n1mda
http://www.codersource.net/winsock_tutorial_server_event_model.html
Posted on 2008-09-26 23:49:57 by Homer
winsock tutorial? Do read this. http://www.madwizard.org/programming/tutorials/netasm/
Posted on 2008-09-27 03:29:17 by roticv
Oh he wanted help with a specific API not basic socket tutorial - the link I gave has what he asked for, whereas Bleek's tutorial does not.

Posted on 2008-09-27 05:19:24 by Homer
I'm having some troubles with WSAEnumNetworkEvents.

invoke WSAEnumNetworkEvents, hSocket, hEvent, addr WSAEvents


I need to initialize WSAEvents as a WSANETWORKEVENTS structure.

.data
WSAEvents WSANETWORKEVENTS


error A2008: syntax error : in structure

How is it initialized in asm? Havn't found any example without a proc or macro.

EDIT: It is initialized like this:
WSAEvents WSANETWORKEVENTS <>
Posted on 2008-10-05 10:23:10 by n1mda
CreateWindow call with the parent set as "HWND_MESSAGE" will let you create a message-only window if you had the experience working with a specific model of winsock and didn't want to mess with the other models.
Posted on 2008-10-15 23:09:45 by jakor
really crappy idea, same fault, gui locked while WM crunches socket messages
Posted on 2008-11-02 22:58:33 by Homer