Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- namespace test
- {
- class Program
- {
- static TcpListener listener;
- static void Main(string[] args)
- {
- listener = new TcpListener(new IPEndPoint(IPAddress.Any, 3349));
- listener.Start();
- listener.BeginAcceptSocket(Accept, null);
- Console.WriteLine("Started!");
- // Simulate a random other client connecting, nc localhost 3349 does the same thing
- var client = new TcpClient();
- client.Connect("localhost", 3349);
- Thread.Sleep(2000);
- listener.Stop();
- Console.WriteLine("Done!");
- }
- static void Accept(IAsyncResult result)
- {
- using(var socket = listener.EndAcceptSocket(result))
- {
- Console.WriteLine("Accepted socket");
- Thread.Sleep(500);
- socket.Shutdown(SocketShutdown.Both);
- }
- Console.WriteLine("Socket fully closed");
- }
- }
- }
- dotnet --version
- 2.1.103
- lsb_release -a
- No LSB modules are available.
- Distributor ID: Ubuntu
- Description: Ubuntu 16.04.4 LTS
- Release: 16.04
- Codename: xenial
Add Comment
Please, Sign In to add comment