System.ObjectDisposedException on WatsonTCPClient.Connect()
See original GitHub issueHi,
I’m think I found a bug on the WatsonTCPClient. Right now I’m using the WatsonTcpClient like this: I do not keep a connection alive, I connect only when I send some data from the client then disconnect. If I send data multiple times in a row like this I get the following error:
System.ObjectDisposedException: "Safe handle has been closed. ObjectDisposed_ObjectName_Name"
Debug Log:
[WatsonTcpClient] connecting to 127.0.0.1:25000 [WatsonTcpClient] exception encountered: { "ClassName": "System.ObjectDisposedException", "Message": "Safe handle has been closed.", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": " at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)\r\n at System.Threading.WaitHandle.WaitOneNoCheck(Int32 millisecondsTimeout)\r\n at System.Threading.WaitHandle.WaitOne(TimeSpan timeout, Boolean exitContext)\r\n at WatsonTcp.WatsonTcpClient.Connect()", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2146232798, "Source": "System.Private.CoreLib", "WatsonBuckets": null, "ObjectName": "SafeHandle" }
Code to reproduce this error: ` // See https://aka.ms/new-console-template for more information
using WatsonTcp;
var s = new WatsonTcpServer(null, 25000); s.Events.MessageReceived += (sender, received_args) => { global::System.Console.WriteLine(“Message Received”); }; s.Callbacks.SyncRequestReceived = (request) => { global::System.Console.WriteLine(“SyncRequestReceived”); return new SyncResponse(request, DateTime.Now.ToString()); };
s.Start();
while (true) { var c = new WatsonTcpClient(“127.0.0.1”, 25000); c.Events.MessageReceived += (s, received_args) => { global::System.Console.WriteLine(“Message received”); }; c.Settings.DebugMessages = true; c.Settings.Logger += (s, m) => { global::System.Console.WriteLine(m); }; c.Connect(); var response = c.SendAndWait(5000, new byte[] { 1, 2, 3 }); Console.ReadLine(); } `
I’m using .Net 6 and the latest WastonTcp version via NuGet 4.8.14.6
Regards
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (8 by maintainers)
Top GitHub Comments
@ahubertus44 dude - thank you. Very generous, I really appreciate it!
Wow, thank you @ahubertus44! My receive address is: 32UAbVDvqRuwsJ4zq8tsamWgjFC9fp8sp8 Much appreciated!