Network programming practice

Just starting out? Need help? Post your questions and find answers here.
netmon
User
User
Posts: 12
Joined: Sun Jul 27, 2003 4:29 pm

Network programming practice

Post by netmon »

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?
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

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?
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.
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?
Sort of, though it's not that simple. Take a gander at this : http://www.codeproject.com/internet/?Display=title

... it's C/C++ stuff, but it's still good reading. You might also search for some windows socket tutorials.
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.
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=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?
Yes, it is.

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
Johan_Haegg
User
User
Posts: 60
Joined: Wed Apr 30, 2003 2:25 pm
Location: Västerås
Contact:

Post by Johan_Haegg »

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 =/
Post Reply