Replies: 3 comments 1 reply
-
Hi @DVonk thanks for the kind words. It likely is indeed a threading problem and where the client runs vs the UI thread. I have a very similar TCP project called WatsonTcp (main difference is WatsonTcp uses a framing layer, SuperSimpleTcp does not) and in that repo I have a test client for Windows forms. Please take a look and let me know if this helps. Syntactically the two projects are almost identical. https://github.com/jchristn/WatsonTcp/blob/master/Test.WinFormClient/ClientForm.cs Specifically:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for the link to the other repository. I've taken a look, but it seems unsuitable as it says I have to use WatsonTcp for the server as well. I do not have control over the server however, I'm just trying to build a TcpClient that can communicate with a closed source server for which I have nothing but IP address and port. So, is it correct that there's actually no way to get the data from SuperSimpleTcp out of the thread it uses? I mean, that's kind of what Tcp is used for - to get data from a server and do something with it in your program. |
Beta Was this translation helpful? Give feedback.
-
Hi @DVonk I think you may have misinterpreted. WatsonTcp and SuperSimpleTcp are very similar in terms of implementation. I wasn't implying that you should use WatsonTcp, but rather, use the model/implementation shown in the WatsonTcp TestWinFormClient project. That code, though written for WatsonTcp, should work as well for SuperSimpleTcp. |
Beta Was this translation helpful? Give feedback.
-
Hello,
first of all - I just recently came across your project after trying to use TcpClient myself and encountering a lot of problems. It's really simple to use and works great so far, so thank you for that. I have one issue though:
How do I actually use the data I'm receiving from the server in DataReceived outside of that function? For example, I want to do this inside of DataReceived on the client's side:
textBox.text = $"[{e.IpPort}] {Encoding.UTF8.GetString(e.Data)}"
This just doesn't do anything, and it even seems to abort the connection without calling ClientDisconnected, as repeated calls of client.Send() lead to this error:
That does not happen when I display the data with MessageBox.Show(), or set a variable to the data. But if I then try to set the TextBox to the variable, nothing happens and the connection aborts.
I'm guessing that this is a threading issue, since I'm trying to change data in the main UI thread. So my question is - how is it intended to get the data out of this DataReceived event, so I can use it normally with the rest of my software?
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions