M
Michel Racicot
I'm quite new to TCP/IP programming, so feel free to tell me that I have the
wrong approach.
So far, I have a WinForm application that can be the client or the client
and server at the same time.
If the application is the server (and client at the same time), I have three
threads (plus my main WinForm thread): A TCPListener, a TCPServer and a
TCPClient connected to the server.
When the Server receive a message, it sends it to all connected client
(including the local client).
If the application is only a client, I have only one thread (plus my main
WinForm thread).
Some message that the TCP Client can receive might indicate that a Window
must be refreshed (example: a new client has been connected and we should
add his name in a listbox for example).
The problem is that since the TCP Client can receive stuff at any moment, I
made it a thread that verify DataAvailable and then read on the Network
Stream and deserialize it to an object. However, threads other than the
main WinForm thread can NOT call methods of WinForms.
One of the suggestion I had, was to put on queue all received messages and
then, on a timer installed on the WinForm thread, unqueue them and threat
them accordingly.
Is that the right thing to do? How is it done by the experts?
If I'm not clear enough, feel free to ask for more infos...
Thank you
wrong approach.
So far, I have a WinForm application that can be the client or the client
and server at the same time.
If the application is the server (and client at the same time), I have three
threads (plus my main WinForm thread): A TCPListener, a TCPServer and a
TCPClient connected to the server.
When the Server receive a message, it sends it to all connected client
(including the local client).
If the application is only a client, I have only one thread (plus my main
WinForm thread).
Some message that the TCP Client can receive might indicate that a Window
must be refreshed (example: a new client has been connected and we should
add his name in a listbox for example).
The problem is that since the TCP Client can receive stuff at any moment, I
made it a thread that verify DataAvailable and then read on the Network
Stream and deserialize it to an object. However, threads other than the
main WinForm thread can NOT call methods of WinForms.
One of the suggestion I had, was to put on queue all received messages and
then, on a timer installed on the WinForm thread, unqueue them and threat
them accordingly.
Is that the right thing to do? How is it done by the experts?
If I'm not clear enough, feel free to ask for more infos...
Thank you