File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
cpp/VS_Snippets_Remoting/NclTcpServerSync/cpp
csharp/System.Net.Sockets/NetworkStream/WriteTimeout Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -31,5 +31,10 @@ int main()
3131 // Stop listening for incoming connections
3232 // and close the server.
3333 tcpListener->Stop ();
34+
35+ // Dispose allocated resources.
36+ delete networkStream;
37+ delete tcpClient;
38+ delete tcpListener;
3439}
3540// </snippet0>
Original file line number Diff line number Diff line change @@ -12,16 +12,16 @@ public static void Main()
1212 {
1313 // Create the server side connection and
1414 // start listening for clients.
15- TcpListener tcpListener = new TcpListener ( IPAddress . Any , 11000 ) ;
15+ using TcpListener tcpListener = new TcpListener ( IPAddress . Any , 11000 ) ;
1616 tcpListener . Start ( ) ;
1717 Console . WriteLine ( "Waiting for a connection...." ) ;
1818
1919 // Accept the pending client connection.
20- TcpClient tcpClient = tcpListener . AcceptTcpClient ( ) ;
20+ using TcpClient tcpClient = tcpListener . AcceptTcpClient ( ) ;
2121 Console . WriteLine ( "Connection accepted." ) ;
2222 // Get the stream to write the message
2323 // that will be sent to the client.
24- NetworkStream networkStream = tcpClient . GetStream ( ) ;
24+ using NetworkStream networkStream = tcpClient . GetStream ( ) ;
2525 string responseString = "Hello." ;
2626 // Set the write timeout to 10 millseconds.
2727 networkStream . WriteTimeout = 10 ;
You can’t perform that action at this time.
0 commit comments