//static Dictionary<ushort, TcpServer> servers = new Dictionary<ushort, TcpServer>(); 

        static public void Start(int local_port, IPAddress destination_ip)
        {
            if (!NetworkRoutines.IsNetworkAvailable())
                throw new Exception("No network available.");
            IPAddress ipAddress = NetworkRoutines.GetLocalIpForDestination(destination_ip);

            if (local_port == LocalPort && ipAddress.Equals(LocalIp))
                return;
            Stop();

            Log.Main.Inform("Starting TCP listener on " + local_port + " for " + destination_ip);

            //listeningSocket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            //listeningSocket.Bind(localEndPoint);
            ////listeningSocket.Listen(100);
            server = new TcpListener(ipAddress, local_port);
            server.Start();

            thread = ThreadRoutines.StartTry(run, (Exception e) =>
            {
                if (e is SocketException)
                {
                    Log.Main.Warning(e);
                }
                else
                {
                    Log.Main.Error(e);
                    CisteraScreenCaptureService.ExposedEvents.UiMessage.Error(Log.GetExceptionMessage(e));
                }
                Stop();
            });
        }
Пример #2
0
        //static Dictionary<ushort, TcpServer> servers = new Dictionary<ushort, TcpServer>();

        static public void Start(int local_port, IPAddress destination_ip)
        {
            if (!NetworkRoutines.IsNetworkAvailable())
            {
                throw new Exception("No network available.");
            }
            IPAddress ipAddress = NetworkRoutines.GetLocalIpForDestination(destination_ip);

            if (local_port == LocalPort && ipAddress.Equals(LocalIp))
            {
                return;
            }
            Stop();

            Log.Main.Inform("Starting TCP listener on " + local_port + " for " + destination_ip);

            //listeningSocket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            //listeningSocket.Bind(localEndPoint);
            ////listeningSocket.Listen(100);
            server = new TcpListener(ipAddress, local_port);
            server.Start();

            thread = ThreadRoutines.StartTry(run, (Exception e) =>
            {
                if (e is SocketException)
                {
                    Log.Main.Warning(e);
                }
                else
                {
                    Log.Main.Error(e);
                    InfoWindow.Create(Log.GetExceptionMessage(e), null, "OK", null, Settings.View.ErrorSoundFile, System.Windows.Media.Brushes.WhiteSmoke, System.Windows.Media.Brushes.Red);
                }
                Stop();
            });
        }