How to react after receiving a packet in TCP server
I am new in C#. I made a very simple TCP server and TCP Client. I am able to send some开发者_如何学运维 message from client to server. If I want see the message which came from client on server I am using button which view the message. Now my stupid question. How make a function which will react on new comming packet from client to view it imediately in textBox? Simple what I want>>> IF comes a new packet......DO SOMETHING.
Generally, a TCP server does this:
- Create a thread to listen for connection requests
- Do a TcpListener.AcceptTcpClient in the above thread
- When AcceptTcpClient accepts a connection, create a new thread
- In new thread, do a GetStream and then Read the stream.
- When data arrives, decode it and send a message to the GUI / Controller / whatever.
- Process the TCP message and send a response message to the TCP thread to Write on the stream the result of the processing.
精彩评论