Hello,
I have developed the client side of a UDP client-server application that will handle about 100 people at a time. I would, however, like some advice on how I should go about building the server. Here's how I have it planned (remember that this is my first try at something like this):
1. The main Thread
- handles form events
- spawns 4 "worker thread"s
- spawns 1 "Master Thread"
2. The Master Thread
- listens for incoming packets
- puts messages into a queue
- checks each thread to see if it is started or not
- if it finds one stopped, activate it
- uses Thread.Start()
- return to listen
3. The worker thread(s)
- Use this sub:
Public queue(100) as string
Public Sub dowork()
...watches the first in the queue (queue(0))
...if it has a message in it, copy it to it's own
personal variables using a custom class.
...delete that message from the queue
...use the custom class for I/O and to handle the command
End Sub
Each person connecting might do a certain amount of work at one time, so I have decided to have an array of user ID's. At the beginning of each message would be the UserID followed by ":" and the command. the worker thread would be able to look at this public userid array and check a corresponding IPEndPoint array to find the users address and port. The worker thread would handle logouts by removing the userid and ipendpoint from the lists and moving the rest down one.
At some point I might add some database calls and I thought I would create 5 more threads for that purpose and do handling that way.
So how does this look? I'm hoping I got it fairly close. One other question: How should I go about making sure only one thread will read/write the Message queue, UserID's and IPEndPoint arrays at one time?
Thank you for your time and advice!
Brian
I have developed the client side of a UDP client-server application that will handle about 100 people at a time. I would, however, like some advice on how I should go about building the server. Here's how I have it planned (remember that this is my first try at something like this):
1. The main Thread
- handles form events
- spawns 4 "worker thread"s
- spawns 1 "Master Thread"
2. The Master Thread
- listens for incoming packets
- puts messages into a queue
- checks each thread to see if it is started or not
- if it finds one stopped, activate it
- uses Thread.Start()
- return to listen
3. The worker thread(s)
- Use this sub:
Public queue(100) as string
Public Sub dowork()
...watches the first in the queue (queue(0))
...if it has a message in it, copy it to it's own
personal variables using a custom class.
...delete that message from the queue
...use the custom class for I/O and to handle the command
End Sub
Each person connecting might do a certain amount of work at one time, so I have decided to have an array of user ID's. At the beginning of each message would be the UserID followed by ":" and the command. the worker thread would be able to look at this public userid array and check a corresponding IPEndPoint array to find the users address and port. The worker thread would handle logouts by removing the userid and ipendpoint from the lists and moving the rest down one.
At some point I might add some database calls and I thought I would create 5 more threads for that purpose and do handling that way.
So how does this look? I'm hoping I got it fairly close. One other question: How should I go about making sure only one thread will read/write the Message queue, UserID's and IPEndPoint arrays at one time?
Thank you for your time and advice!
Brian