Please forgive the length, Im trying to be detailed as possible.
Before I start, because of the flexibility and me being a massive control freak, please dont suggest me using the TCPclient class. I have a massive need to know exactly how my data is being handled. Also, since its a comparitively difficult class, its very good practice in networking logic. Thanks
Im 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.
Ive devised many ways of buffering on the receiving end of the class. Ill go over a sending question in a different post . Here is the basic idea ive 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 Id like to do is create a memorystream and set the capacity with this length. Ive 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. Im 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, Id like this socket to be able to handle everything from a simple chat program, to a file transfer (ive 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, Ive 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 dont suggest me using the TCPclient class. I have a massive need to know exactly how my data is being handled. Also, since its a comparitively difficult class, its very good practice in networking logic. Thanks
Im 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.
Ive devised many ways of buffering on the receiving end of the class. Ill go over a sending question in a different post . Here is the basic idea ive 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 Id like to do is create a memorystream and set the capacity with this length. Ive 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. Im 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, Id like this socket to be able to handle everything from a simple chat program, to a file transfer (ive 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, Ive never trusted delimiters to be 100% accurate.
Thanks for even reading this!
- Mark