This example shares the specific code for C# reading socket timeout settings in streaming mode for your reference. The specific content is as follows
using System; using ; using ; using ; using ; public class client { public static void Main() { try { // Create a new client socketTcpClient tcpclnt = new TcpClient(); ("connect....."); // Connect to the server = 3000;//Set the Socket's reception timeout time is 3S.("127.0.0.1",8001); ("Connected"); ("Please enter the string to be transferred: "); // Read in stringString str=(); // Get the client's streamStream stm = (); // Send stringASCIIEncoding asen= new ASCIIEncoding(); byte[] ba=(str); ("In transit..."); (ba,0,); // Receive information returned from the serverbyte[] bb=new byte[100]; int k=(bb,0,100); //The timeout exception will occur after 3 seconds // Output server return information for (int i=0;i { ((bb[i])); } // Close client connection(); } catch (Exception e) { ("Error..... " + ); } } }
The TCPListener class is used to listen to client connection requests, and the TCPClient class is used to provide local hosts and
Connection information for the remote host.
Both classes are located in the namespace
Commonly used methods of TCPListener class.
Method
AcceptSocket Receive a connection from the port and assign it the Socket object
AcceptTcpClient Receive a connection from the port and assign it the TCPClient object
Equals �
GetType �
Pending �
Start
Stop �
ToString
So when we use TcpListener to listen to the port, once the connection is established, we can also get a tcpclient object, and the timeout can be set by reading and writing the data.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.