- Server instead of receiving 255 bytes, receives 1 byte at a time. When no more data is received it sends to the player. More efficient, less memory usage, no possibility of data cutoff.
This commit is contained in:
parent
7b0d761879
commit
631ce62e73
1 changed files with 9 additions and 3 deletions
|
@ -94,14 +94,20 @@ namespace MudEngine.Networking
|
||||||
private void ReceiveThread(object obj)
|
private void ReceiveThread(object obj)
|
||||||
{
|
{
|
||||||
int sub = (int)obj;
|
int sub = (int)obj;
|
||||||
|
List<byte> buffer = new List<byte>();
|
||||||
while (stage == 2 && players[sub].IsActive)
|
while (stage == 2 && players[sub].IsActive)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte[] buf = new byte[255];
|
byte[] buf = new byte[1];
|
||||||
int recved = players[sub].client.Receive(buf);
|
int recved = players[sub].client.Receive(buf);
|
||||||
if(recved > 0)
|
if (recved > 0)
|
||||||
players[sub].Receive(buf);
|
buffer.Add(buf[0]);
|
||||||
|
else if (buffer.Count > 0)
|
||||||
|
{
|
||||||
|
players[sub].Send(buffer.ToArray());
|
||||||
|
buffer.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception) // error receiving, close player
|
catch (Exception) // error receiving, close player
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue