コード例 #1
0
        public void ConnectionTimeoutTestWithThread()
        {
            int    timeoutSec          = 5;
            string connStrNotAvailable = $"Server=tcp:fakeServer,1433;uid=fakeuser;pwd=fakepwd;Connection Timeout={timeoutSec}";

            List <ConnectionWorker> list = new List <ConnectionWorker>();

            for (int i = 0; i < 10; ++i)
            {
                list.Add(new ConnectionWorker(connStrNotAvailable));
            }

            ConnectionWorker.Start();
            ConnectionWorker.Stop();

            double theMax = 0;

            foreach (ConnectionWorker w in list)
            {
                if (theMax < w.MaxTimeElapsed)
                {
                    theMax = w.MaxTimeElapsed;
                }
            }

            int threshold = (timeoutSec + 1) * 1000;

            Console.WriteLine($"ConnectionTimeoutTestWithThread: Elapsed Time {theMax} and threshold {threshold}");
        }
コード例 #2
0
        public static void ConnectionTimeoutTestWithThread()
        {
            const int timeoutSec   = 5;
            const int numOfTry     = 2;
            const int numOfThreads = 5;

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString);

            builder.DataSource     = "invalidhost";
            builder.ConnectTimeout = timeoutSec;
            string connStrNotAvailable = builder.ConnectionString;

            for (int i = 0; i < numOfThreads; ++i)
            {
                new ConnectionWorker(connStrNotAvailable, numOfTry);
            }

            ConnectionWorker.Start();
            ConnectionWorker.Stop();

            double timeTotal   = 0;
            double timeElapsed = 0;

            foreach (ConnectionWorker w in ConnectionWorker.WorkerList)
            {
                timeTotal += w.TimeElapsed;
            }
            timeElapsed = timeTotal / Convert.ToDouble(ConnectionWorker.WorkerList.Count);

            int threshold = timeoutSec * numOfTry * 2 * 1000;

            Assert.True(timeElapsed < threshold);
        }
コード例 #3
0
        public ClientPlayer(int id, ConnectionWorker worker)
        {
            this.id      = id;
            this.worker  = worker;
            chunkPosList = new List <WorldPos>();
//			renderChunkPosList = new List<WorldPos>();
            viewPlayers = new List <int>();
            viewWidth   = VIEW_WIDTH;
        }
コード例 #4
0
 /// <summary>
 /// Creates a new Connection to the server
 /// </summary>
 public Client()
 {
     // Connecting to the server
     Connection             = new ConnectionWorker(ConnectionSettings.Instance.server, ConnectionSettings.Instance.port);
     Connection.Established = ConnectionEstablished;
     Connection.Received    = DataReceived;
     Connection.Terminated  = ConnectionTerminated;
     Threads = new List <Thread>();
     Status  = new UserStatus();
 }
コード例 #5
0
//	private bool IsPortUse(int port)
//	{
//		IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
//		IPEndPoint[] arr = properties.GetActiveUdpListeners();
//		foreach (var item in arr) {
//			Debug.Log("udpPort:" + item.Port);
//			if(item.Port == port)return true;
//		}
//		return false;
//	}

    public void StopBroadcast()
    {
        if (!stop)
        {
            try
            {
                broadcastWorker.Stop();
                broadcastWorker.Dispose();
                broadcastWorker = null;
                stop            = true;
            }catch (Exception e)
            {
                GUITextDebug.debug(e.Message + "\n" + e.StackTrace);
            }
        }
    }
コード例 #6
0
        private void Connect()
        {
            try
            {
                var socket = new TcpClient(_terminalHost, _terminalPort)
                {
                    NoDelay = true
                };
                //
                _connectionWorker = new ConnectionWorker(socket);
//                ThreadPool.QueueUserWorkItem(_connectionWorkerThread.Run);
//                var t = new Thread(_connectionWorkerThread.Run) {IsBackground = true};
//                t.Start();
                //
                const int receiveTimeout = 60000;
                socket.ReceiveTimeout = receiveTimeout;
                var s = Ask("HELLO" + _myName + "\u0001" + Version.NJ4X + "\u0001" + Version.NJ4X_UUID);
                socket.ReceiveTimeout = 0;
                if (s == null || s.Equals("NONE"))
                {
                    // peer disconnected
                    throw new Exception("Socket read timeout: " + receiveTimeout);
                }
                var ix = s.LastIndexOf('\u0001');
                TSVersion = ix > 0 ? s.Substring(ix + 1) : "1.7.1";
                _connectionWorker.PeerName = s.Substring(5, ix > 0 ? ix - 5 : s.Length - 5);
                if (s.StartsWith("HELLO"))
                {
                    if (String.Compare(TSVersion, MinimumTsVersion, StringComparison.Ordinal) < 0)
                    {
                        throw new Exception("Unsupported Terminal Server version: " + TSVersion);
                    }
                }
                else
                {
                    throw new Exception("Unsupported NJ4X API version (" + Version.NJ4X + ") by Terminal Server (v" +
                                        TSVersion + ")");
                }
            }
            catch (Exception e)
            {
                Close();
                Logger.Fatal("Could not establish connection to terminal server: " + _terminalHost + ':' +
                             _terminalPort, e);
                throw;
            }
        }
コード例 #7
0
 public void StartBroadcast()
 {
     if (stop)
     {
         try
         {
             UdpConnection udpConnection = new UdpConnection(broadcastPort);
             broadcastWorker = new ConnectionWorker(udpConnection);
             broadcastWorker.Start();
             stop = false;
             StartCoroutine(ListenReceive());
         }
         catch (Exception e)
         {
             GUITextDebug.debug(e.Message + "\n" + e.StackTrace);
         }
     }
 }
コード例 #8
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     ConnectionWorker.CancelAsync();
     game.connection.Disconnect();
 }
コード例 #9
0
ファイル: Form1.cs プロジェクト: unqx/KursNetworks
 private void Form1_Load(object sender, EventArgs e)
 {
     ConnectionWorker.RunWorkerAsync();
     TransmittingWorker.RunWorkerAsync();
     DownloadButton.Enabled = false;
 }