Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Proud committed Jul 15, 2023
2 parents bc440cf + 269357c commit 845f0ba
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,26 @@ public void Open(TcpClient client)

while(isOpen)
{
while ((position = stream.Read(buffer, 0, buffer.Length)) != 0 && isOpen)
if (clientDisconnected())
{
data = Encoding.UTF8.GetString(buffer, 0, position);
var args = new DataReceivedArgs()
Close();
}
else
{
while ((position = stream.Read(buffer, 0, buffer.Length)) != 0 && isOpen)
{
Message = data,
ConnectionId = Id,
ThisChannel = this
};
data = Encoding.UTF8.GetString(buffer, 0, position);
var args = new DataReceivedArgs()
{
Message = data,
ConnectionId = Id,
ThisChannel = this
};

thisServer.OnDataIn(args);
if(!isOpen) { break; }
thisServer.OnDataIn(args);
if(!isOpen) { break; }
}
}

}
}
}
Expand All @@ -62,6 +68,7 @@ public void Send(string message)
stream.Write(data, 0, data.Length);
}


public void Close()
{
Dispose(false);
Expand All @@ -88,5 +95,10 @@ public void Dispose()
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

private bool clientDisconnected()
{
return (thisClient.Client.Available == 0 && thisClient.Client.Poll(1, SelectMode.SelectRead));
}
}
}

0 comments on commit 845f0ba

Please sign in to comment.