System.Net.Sockets.NetworkStream.Close C# (CSharp) Method

Close() public method

public Close ( int timeout ) : void
timeout int
return void
        public void Close(int timeout)
        {
#if DEBUG
            using (DebugThreadTracking.SetThreadKind(ThreadKinds.User | ThreadKinds.Sync))
            {
#endif
                if (timeout < -1)
                {
                    throw new ArgumentOutOfRangeException(nameof(timeout));
                }
                _closeTimeout = timeout;
                Dispose();
#if DEBUG
            }
#endif
        }
        private volatile bool _cleanedUp = false;

Usage Example

        public override void Insert(Person person)
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect(IPAddress.Parse("127.0.0.1"), 3180);

            NetworkStream networkStream = new NetworkStream(socket);

            string dataSend = extension + "|" + "Insert|" + person.ToXML();

            byte[] bytes = Encoding.UTF8.GetBytes(dataSend);
            networkStream.Write(bytes, 0, bytes.Length);

            bool isWork = true;
            while (isWork)
            {
                if (networkStream.DataAvailable)
                {
                    isWork = false;
                    byte[] buffer = new byte[socket.Available];
                    networkStream.Read(buffer, 0, buffer.Length);
                    string result = Encoding.UTF8.GetString(buffer);
                }
            }
            networkStream.Flush();
            networkStream.Close();
            socket.Close();
        }
All Usage Examples Of System.Net.Sockets.NetworkStream::Close