Yuki, when implementing a packet splitter you might want to enqueue everything you get and then split from the top and not directly what you get from the receive function. On localhost it won't make a difference but on the Internet it will.
Packet buffering is not only part of TCP/IP. Anyway, you need a packet splitter, but also you need to handle packet fragmentation, which is something else.
Well, I guess we all see why it doesnt work dont we?
You do realize it's a terrible idea to use more than a single thread for packet processing, right? I'm talking about your usage of the ThreadPool class.
You do realize it's a terrible idea to use more than a single thread for packet processing, right? I'm talking about your usage of the ThreadPool class.
That's not good advice either though. Multithreading is definitely a good idea for packet processing, but using a ThreadPool from C# is not. Managing your own worker threads and the number of threads processing requests at one given time is optimal. A single thread processing all requests for a server... bad idea.
Edit: Also, I have a packet splitter / fragment handler for my server that should be more or less public on my blog. I think I made modifications to it in my project since posting it on my blog, but it should work as is. Step through the design before implementing it.
That's not good advice either though. Multithreading is definitely a good idea for packet processing, but using a ThreadPool from C# is not. Managing your own worker threads and the number of threads processing requests at one given time is optimal. A single thread processing all requests for a server... bad idea.
Edit: Also, I have a packet splitter / fragment handler for my server that should be more or less public on my blog. I think I made modifications to it, but it should work as is.
... you might as well just use UDP then, if you don't care in what order your packets are processed
... you might as well just use UDP then, if you don't care in what order your packets are processed
TCP sends packets in order, thus the server receives packets in order. For things that need to be processed one at a time, use queues. Processing all packets on one thread is idiotic - it's just going to bottleneck at the packet handler.
TCP sends packets in order, thus the server receives packets in order.
Player jumps from position 300, 300 to 300, 310 and sends packet A to the server with this information.
Player jumps from position 300, 310 to 300, 320 and sends packet B to the server with this information.
The server receives packet A and B in the correct order, because the server uses TCP.
The server uses a thread pool to process packets, so both packet A and B are submitted to the thread pool for processing.
The server uses thread A for processing packet A and thread B for processing packet B.
While processing packet A in thread A, the operating system suddenly decides to stop thread A before it's done processing and gives thread B time to run.
Thread B happens to complete the processing of packet B and now the operating system gives time for thread A to continue again.
What happens then? The client is going to get disconnected because the server processed the packets in the wrong order: it thinks that the player jumped from 300, 300 to 300, 320 (distance = 20 ==> disconnect).
Player jumps from position 300, 300 to 300, 310 and sends packet A to the server with this information.
Player jumps from position 300, 310 to 300, 320 and sends packet B to the server with this information.
The server receives packet A and B in the correct order, because the server uses TCP.
The server uses a thread pool to process packets, so both packet A and B are submitted to the thread pool for processing.
The server uses thread A for processing packet A and thread B for processing packet B.
While processing packet A in thread A, the operating system suddenly decides to stop thread A before it's done processing and gives thread B time to run.
Thread B happens to complete the processing of packet B and now the operating system gives time for thread A to continue again.
What happens then? The client is going to get disconnected because the server processed the packets in the wrong order: it thinks that the player jumped from 300, 300 to 300, 320 (distance = 20 ==> disconnect).
This. For the last week I`ve been rewriting the way we handled packets for a rather large project at my job for exactly the same reason.
[Request]Buy from shop packetID 11/06/2009 - CO2 Private Server - 4 Replies using ConquerPatch._5017;
I`d need the packetID of the packet that allows you to buy stuff from shops, or if it`s a subtype of a packet, then the ID and the subtype. Btw, if anyone has a list of the PacketIDs (just the IDs, not the codes) for 5017, I`d be really grateful.
MessageBoard PacketID? 07/26/2009 - CO2 Private Server - 5 Replies Heya.
Was just wondering if anyone has the messageboard packetid to make a text be written in the messageboard. I got so far that I can get what message the user inputs in the window, but not sure how to get it to write a text in the board.
Thanks.