开发者

How to react after receiving a packet in TCP server

开发者 https://www.devze.com 2023-02-28 13:28 出处:网络
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 u

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:

  1. Create a thread to listen for connection requests
  2. Do a TcpListener.AcceptTcpClient in the above thread
  3. When AcceptTcpClient accepts a connection, create a new thread
  4. In new thread, do a GetStream and then Read the stream.
  5. When data arrives, decode it and send a message to the GUI / Controller / whatever.
  6. Process the TCP message and send a response message to the TCP thread to Write on the stream the result of the processing.
0

精彩评论

暂无评论...
验证码 换一张
取 消