Right now i am testing server/client programming, and my current model uses threads to monitor network activity per client. what would be the best solution to handle network traffic?
Lets say there are many users logged into the server. Now if every user sent data to the server at one time do the packets just sit and wait until the server gets around to responding to each clients requests?
And about threads, Is it safe to assume that once the thread is created, the procedure that was used is always being called, like an infinite loop so to speak. basicly, is there any need for me to use a repeat/until loop in a thread.
Is it good practice to have the client/sever send each other the packet size being sent each time before the actual packet is sent?
And can a thread kill its own thread without any problems?
Network programming practice
Threads are still pretty dangerous stuff in PB (and in general really). For instance PB strings aren't thread safe and I think I read something about it's memory allocation routines not being thread safe either. Regardless, it's possible to use a threaded model - I can't really speak to that being the best way though.Right now i am testing server/client programming, and my current model uses threads to monitor network activity per client. what would be the best solution to handle network traffic?
Sort of, though it's not that simple. Take a gander at this : http://www.codeproject.com/internet/?Display=titleLets say there are many users logged into the server. Now if every user sent data to the server at one time do the packets just sit and wait until the server gets around to responding to each clients requests?
... it's C/C++ stuff, but it's still good reading. You might also search for some windows socket tutorials.
No, that's not really what a thread is - it's not really correct to think of a thread as a single procedure. Though you create a thread and pass it a single procedure's address - that procedure could in turn call a million more. What happens in a thread is all up to the programmer. This is a decent read about threads : viewtopic.php?t=6296&highlight=threadAnd about threads, Is it safe to assume that once the thread is created, the procedure that was used is always being called, like an infinite loop so to speak. basicly, is there any need for me to use a repeat/until loop in a thread.
Yes, it is.Is it good practice to have the client/sever send each other the packet size being sent each time before the actual packet is sent?
I did what I think is a decent network example (though it doesn't use threads), check it out here :
http://www.purebasic.org/index.php?id=C0_1_1
I'll be putting up some more networking stuff there pretty soon.
Good luck!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
-
- User
- Posts: 60
- Joined: Wed Apr 30, 2003 2:25 pm
- Location: Västerås
- Contact:
i myself use a for/next loop to handle all users in turn, quite safe and good for sending large amounts of data without eating up the last bit of CPU-power.
Just posted about it in:
viewtopic.php?t=6940
Wrote a multithreaded webserver once, its quite stable (runs for 2 days without crash)
But its terribly slow and misses some requests, my main use for it is to upload files to my Linux-gateway with wget, to bad i lost the source a while ago =/
Just posted about it in:
viewtopic.php?t=6940
Wrote a multithreaded webserver once, its quite stable (runs for 2 days without crash)
But its terribly slow and misses some requests, my main use for it is to upload files to my Linux-gateway with wget, to bad i lost the source a while ago =/