🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

newbie questions

Started by
3 comments, last by a2k 23 years, 11 months ago
please don''t hate me for asking newbie questions. i know how everyone hates dx vs. ogl questions, but i don''t know what the networking equivalent of them would be. do i have to use win32 or MFC(no way) for asynchronous sockets in winsock? or would i be able to use asyncsockets in a console app? if i DO have to code it in win32, the WindowProc function doesn''t act as multi-threading, does it? and how would i implement winsock (async sockets) into a win32 app anyway? for starters, i just want to be able to accept a single user input(via getasynckeystate), send it to the other computer, and allow the other user to do the same thing, and send it to the local computer, just to see how to send data over (basic boolean real-time toggles), and to see if the write on/off data is received on the other computer. i''ve gone through many articles/tutorials, but not much on async sockets, and winsock 2.0 the book, is sold out. i hope async sockets is not as hard as i think..... a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Advertisement
Async sockets are pretty straightforward. You can use Async sockets in a console application, just use WSAEventSelect supplying an event instead of WSAAsyncSelect with an HWND. Then you can poll or block on that event.
You can use the AsynchEventSelect in a console app. If you want to use the AsynchSelect model (which is a little easier IMO) then you''ll need to use win32 SDK or MFC. Both of the above are asynchronous, one posts to a window and one posts to a structure, basically. I won''t go much more into detail than that because I don''t feel like writing a novel right now.

For your second question, not it doesn''t act as multi-threading. You can easily set it up to be multithreaded if you want, but it isn''t necessary. Windows posts messages from the sockets and they are then handled by the wndproc. Hopefully you can find a copy of Network Programming for MS Windows. It''s a pretty good book.

Asynch sockets are not hard to program, don''t sweat it.

-BacksideSnap-

The WSAEventSelect and WSAEnumNetworkEvents functions are provided to accommodate applications such as daemons and services that have no user interface (and hence do not use Windows handles). The WSAEventSelect function behaves exactly like the WSAAsyncSelect function. However, instead of causing a Windows message to be sent on the occurrence of an FD_XXX network event (for example, FD_READ and FD_WRITE), an application-designated event object is set.

Also, the fact that a particular FD_XXX network event has occurred is "remembered" by the service provider. The application can call WSAEnumNetworkEvents to have the current contents of the network event memory copied to an application-supplied buffer and to have the network event memory automatically cleared. If needed, the application can also designate a particular event object that is cleared along with the network event memory.

// CHRIS
// CHRIS [win32mfc]
i've decided to just go for win 32. so is this the right idea?

gamemain()
{
while(1)
{
userinput(){....bool receivedata......};
update positions(){.....bool senddata.....};
render();
}
}


LRESULT CALLBACK windproc(..)
{
case WM_CREATE:
...
case WM_SOCKET:
switch(wsagetselectevent(lparam))
case FD_READ
if(receivedata)
recv()
decode packet()
store values in buffer
case FD_WRITE
if(senddata)
encode and format packet()
send
case ....
...
}


in this pseudocode, i have the winproc WM_SOCKET message enabled by a boolean in the game loop. is this how it would go more or less?




Edited by - a2k on July 12, 2000 2:03:51 PM
------------------General Equation, this is Private Function reporting for duty, sir!a2k

This topic is closed to new replies.

Advertisement