Skip to content
This repository was archived by the owner on Dec 23, 2022. It is now read-only.

Commit fc7aa98

Browse files
committed
Fixed ObjectDisposedException
Added contributor
1 parent 191bc6f commit fc7aa98

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

RCONServerLib/RemoteConClient.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,19 @@ public void SendCommand(string command, CommandResult resultFunc)
197197
/// <exception cref="Exception">Not connected</exception>
198198
private void SendPacket(RemoteConPacket packet)
199199
{
200-
if (!_client.Connected)
200+
if (_client == null || !_client.Connected)
201201
throw new Exception("Not connected.");
202202

203203
var packetBytes = packet.GetBytes();
204-
//_ns.Write(packetBytes, 0, packetBytes.Length);
205-
_ns.BeginWrite(packetBytes, 0, packetBytes.Length - 1, ar => { _ns.EndWrite(ar); }, null);
204+
205+
try
206+
{
207+
_ns.BeginWrite(packetBytes, 0, packetBytes.Length - 1, ar => { _ns.EndWrite(ar); }, null);
208+
}
209+
catch (ObjectDisposedException)
210+
{
211+
// Do not write to socket when its disposed.
212+
}
206213
}
207214

208215
/// <summary>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ public static class Program
201201

202202
Not much here yet. Feel free to fork and sent pull-requests.
203203

204+
* [TWaalen](https://github.com/TWaalen) for fixing the UnitTests
205+
204206
## ToDo List
205207

206208
* [ ] Split packets at 4096 bytes

0 commit comments

Comments
 (0)