Re: Winsock, Multithreading
Quote:
Originally Posted by azteched
FYI, multithreading is not the cure-all solution to creating high performance networked apps. Worry about the I/O model you want to use, then think how you need to implement it.
Of course if you use VB, the I/O model choice is rather limited (blocking, non-blocking, non-blocking with windows message notification) and the best techniques aren't feasible to implement in VB.
Disclaimer in case VB purists want to flame ( ;) ): VB will work just fine for a low-client count server.
Can you elaborate as to why the best techniques aren't feasible in VB? Also, I've seen the following terms in my searches:
Multithreading
Asynchronous I/O
Overlapped I/O
I/O Completion sockets
Are all of these the same? Thanks for any replies/clarifications.
VBAhack
1 Attachment(s)
Re: Winsock, Multithreading
I'm actually in the process of doing the same thing you are. In my case, I'm translating CircleMud to VB for some coding practice. I think you'll be fine using VB for your codebase as long as you do as much through the APIs as you possibly can. This means:
Step One. Read about Berkeley sockets and the Winsock API.
Step Two. Resist the urge to use a Winsock control.
Step Three. Read about Berkeley sockets and the Winsock API again.
Step Four. Try to implement your socket routines.
Step Five. Read about Berkeley sockets and the Winsock API again.
Setp Six. Repeat step four.
Then you should be able to get it off the ground. Personally, I'm at step four ;) . Couple of things to keep in mind. First, you probably don't want to make your server event driven because this would prevent you from keeping all of your connections acting in the same timespace. Second, you probably don't want to multi-thread anything except for your administration functions, for the same reason. I'm doing mine as a activeX dll and exposing functionality to put an administrative interface on top of it. Finally, you need to use string handling functions that are faster than those that VB gives you, as this will be the biggest time-sink for you. I found a string class somewhere (might have been on the forums here-will check when I'm on my other machine) that smokes compared to VB. Some stuff to get you started:
http://www.vbip.com/winsock-api/default.asp
Attached is the current state of my game-loop code. I've moved to implementing the object structures and can't test this until I'm done, so it might not work at all as written now. Note also that I'm writing VB directly over the C source, so it isn't organized to my taste yet, but you will get more out of it if you can read C.
BTW, if you use any of the code in the example, you will need to comply with the CircleMud license, which can be found here:
http://www.circlemud.org/license.html