Hi,
I'm playing around with winsock but having some troubles with WSAASyncSelect.
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
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
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.
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.
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 :)
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?
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?
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.
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 :)
forget 2.0 - if you can use 2.0, then you can use 2.2
forget 2.0 - if you can use 2.0, then you can use 2.2
Yeah, I meant "the new one" (2.2 IIRC) ^^
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?
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?
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
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
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.
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() :)
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!
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!
http://www.codersource.net/winsock_tutorial_server_event_model.html
winsock tutorial? Do read this. http://www.madwizard.org/programming/tutorials/netasm/
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.
I'm having some troubles with WSAEnumNetworkEvents.
I need to initialize WSAEvents as a WSANETWORKEVENTS structure.
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:
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 <>
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.
really crappy idea, same fault, gui locked while WM crunches socket messages