Please forgive the length, I'm trying to be detailed as possible.
Before I start, because of the flexibility and me being a massive control freak, please don't suggest me using the TCPclient class. I have a massive need to know exactly how my data is being handled. Also, since it's a comparitively difficult class, it's very good practice in networking logic. Thanks
I'm working on a very low level socket class. My goal is to make it use packets by using a length field to determine when packets are fully received. Having this happen at such a low level removes the need for it in referring applications and the like and allows me to optimize the low level socket without having to redo any of those apps.
I've devised many ways of buffering on the receiving end of the class. I'll go over a sending question in a different post . Here is the basic idea i've come up with.
Using the beginreceive routine, data is pumped into tempbuffer() from the start. The very first thing received is a segment with the length field prepended to it. Now, since the length is a fixed size of the 4 byte int32, i just read the first 4 bytes, then... This is where I start to run into ease of code/performance issues. What I'd like to do is create a memorystream and set the capacity with this length. I've thought about everytime I receive a peice of data, I check to see how much is needed then copy to the stream up to that length then start a new packet whenever needed. Unfortunately, since you can no longer set the lower bound of an array, the code starts getting confusing when working with lengths and upper bounds. So, the easiest and extremely understandable way of filling the stream is to go byte by byte in tempbuffer() and add it to the stream. After each byte, check to see if it is full. I'm wondering, since theoretically this class should be able to handle a large amount of receives goin on asyncronously, would this constant loop degrade performance?
What sounds like the optimal way of doing this?
One last thing, I'd like this socket to be able to handle everything from a simple chat program, to a file transfer (i've pretty much got a way of doing this w/o the above system) to a MMOG. So, any suggestions of a better way is much appreciated. Anything except a delimiter system is acceptable, I've never trusted delimiters to be 100% accurate.
Thanks for even reading this!
- Mark
Before I start, because of the flexibility and me being a massive control freak, please don't suggest me using the TCPclient class. I have a massive need to know exactly how my data is being handled. Also, since it's a comparitively difficult class, it's very good practice in networking logic. Thanks
I'm working on a very low level socket class. My goal is to make it use packets by using a length field to determine when packets are fully received. Having this happen at such a low level removes the need for it in referring applications and the like and allows me to optimize the low level socket without having to redo any of those apps.
I've devised many ways of buffering on the receiving end of the class. I'll go over a sending question in a different post . Here is the basic idea i've come up with.
Using the beginreceive routine, data is pumped into tempbuffer() from the start. The very first thing received is a segment with the length field prepended to it. Now, since the length is a fixed size of the 4 byte int32, i just read the first 4 bytes, then... This is where I start to run into ease of code/performance issues. What I'd like to do is create a memorystream and set the capacity with this length. I've thought about everytime I receive a peice of data, I check to see how much is needed then copy to the stream up to that length then start a new packet whenever needed. Unfortunately, since you can no longer set the lower bound of an array, the code starts getting confusing when working with lengths and upper bounds. So, the easiest and extremely understandable way of filling the stream is to go byte by byte in tempbuffer() and add it to the stream. After each byte, check to see if it is full. I'm wondering, since theoretically this class should be able to handle a large amount of receives goin on asyncronously, would this constant loop degrade performance?
What sounds like the optimal way of doing this?
One last thing, I'd like this socket to be able to handle everything from a simple chat program, to a file transfer (i've pretty much got a way of doing this w/o the above system) to a MMOG. So, any suggestions of a better way is much appreciated. Anything except a delimiter system is acceptable, I've never trusted delimiters to be 100% accurate.
Thanks for even reading this!
- Mark