当前位置: 首页>>代码示例>>C#>>正文


C# StringSocket.Close方法代码示例

本文整理汇总了C#中CustomNetworking.StringSocket.Close方法的典型用法代码示例。如果您正苦于以下问题:C# StringSocket.Close方法的具体用法?C# StringSocket.Close怎么用?C# StringSocket.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CustomNetworking.StringSocket的用法示例。


在下文中一共展示了StringSocket.Close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestWordCommand5

            public void TestWordCommand5()
            {
                // Assert that an illegal word with more than 3 characters decrements the players
                // score.

                // This will coordinate communication between the threads of the test cases
                mre1 = new ManualResetEvent(false);
                mre2 = new ManualResetEvent(false);

                // Create a two clients to connect with the Boggle Server.
                TcpClient TestClient1 = new TcpClient("localhost", 2000);
                TcpClient TestClient2 = new TcpClient("localhost", 2000);

                // Create a client socket and then a client StringSocket.
                Socket ClientSocket1 = TestClient1.Client;
                Socket ClientSocket2 = TestClient2.Client;
                StringSocket ClientSS1 = new StringSocket(ClientSocket1, new UTF8Encoding());
                StringSocket ClientSS2 = new StringSocket(ClientSocket2, new UTF8Encoding());

                try
                {
                    // Connect two clients together to play Boggle.
                    ClientSS1.BeginSend("PLAY Client1\n", (e, o) => { }, null);
                    ClientSS2.BeginSend("PLAY Client2\n", (e, o) => { }, null);

                    ClientSS1.BeginReceive(CompletedReceive1, 1);
                    ClientSS2.BeginReceive(CompletedReceive2, 3);
                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");

                    // Get all of the Illegal words from the gameboard for these two players.
                    HashSet<string> IlegalWords = FindIllegalWords(GameboardString);

                    // One player plays an illegal word. Assert that the score changes for each
                    // player appropriately.
                    ClientSS1.BeginSend("WORD xxxxxx\n", (e, o) => { }, null);

                    mre1 = new ManualResetEvent(false);
                    mre2 = new ManualResetEvent(false);
                    ClientSS1.BeginReceive(CompletedReceive1, 2);
                    ClientSS2.BeginReceive(CompletedReceive2, 3);

                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual("SCORE -1 0", s1);

                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");
                    Assert.AreEqual("SCORE 0 -1", s2);
                }
                finally
                {
                    ClientSS1.Close();
                    ClientSS2.Close();
                }
            }
开发者ID:jon-whit,项目名称:PS8,代码行数:54,代码来源:BoggleServerTests.cs

示例2: CloseSocketCallback

 /// <summary>
 /// Closes Sockets after WebPage has fully loaded.
 /// </summary>
 private void CloseSocketCallback(StringSocket ss)
 {
     if (ss != null)
     {
         ss.Close();
     }
 }
开发者ID:ryoia,项目名称:BoggleGames,代码行数:10,代码来源:BS.cs

示例3: TestWordCommand6

            public void TestWordCommand6()
            {
                // Test the case in which a the two clients play the same word.

                // This will coordinate communication between the threads of the test cases
                mre3 = new ManualResetEvent(false);
                mre4 = new ManualResetEvent(false);
                mre5 = new ManualResetEvent(false);
                mre6 = new ManualResetEvent(false);

                // Create a two clients to connect with the Boggle Server.
                TcpClient TestClient1 = new TcpClient("localhost", 2000);
                TcpClient TestClient2 = new TcpClient("localhost", 2000);

                // Create a client socket and then a client StringSocket.
                Socket ClientSocket1 = TestClient1.Client;
                Socket ClientSocket2 = TestClient2.Client;
                StringSocket ClientSS1 = new StringSocket(ClientSocket1, new UTF8Encoding());
                StringSocket ClientSS2 = new StringSocket(ClientSocket2, new UTF8Encoding());

                try
                {
                    // Connect two clients together to play Boggle.
                    ClientSS1.BeginSend("PLAY Client1\n", (e, o) => { }, null);
                    ClientSS2.BeginSend("PLAY Client2\n", (e, o) => { }, null);

                    ClientSS1.BeginReceive(CompletedReceive1, 1);
                    ClientSS2.BeginReceive(CompletedReceive2, 2);
                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");

                    // Get all of the legal words from the gameboard for these two players.
                    HashSet<string> LegalWords = FindLegalWords(GameboardString);

                    // One player plays a legal word. Assert that the score changes for each
                    // player appropriately.
                    ClientSS2.BeginSend("WORD " + LegalWords.ElementAt(0) + "\n", (e, o) => { }, null);

                    ClientSS1.BeginReceive(CompletedReceive3, 3);
                    ClientSS2.BeginReceive(CompletedReceive4, 4);

                    Assert.AreEqual(true, mre3.WaitOne(timeout), "Timed out waiting 3");
                    Assert.AreEqual("SCORE 0 1", s3);

                    Assert.AreEqual(true, mre4.WaitOne(timeout), "Timed out waiting 4");
                    Assert.AreEqual("SCORE 1 0", s4);

                    ClientSS1.BeginSend("WORD " + LegalWords.ElementAt(0) + "\n", (e, o) => { }, null);

                    ClientSS1.BeginReceive(CompletedReceive5, 5);
                    ClientSS2.BeginReceive(CompletedReceive6, 6);

                    Assert.AreEqual(true, mre5.WaitOne(timeout), "Timed out waiting 5");
                    Assert.AreEqual("SCORE 0 0", s5);

                    Assert.AreEqual(true, mre6.WaitOne(timeout), "Timed out waiting 6");
                    Assert.AreEqual("SCORE 0 0", s6);
                }
                finally
                {
                    ClientSS1.Close();
                    ClientSS2.Close();
                }
            }
开发者ID:jon-whit,项目名称:PS8,代码行数:64,代码来源:BoggleServerTests.cs

示例4: IllegalClientProtocol

            /// <summary>
            /// Test to determine if two clients send the proper START commands initially. 
            /// If they don't then the server will reply with an IGNORING command.
            /// </summary>
            public void IllegalClientProtocol()
            {
                // This will coordinate communication between the threads of the test cases
                mre1 = new ManualResetEvent(false);
                mre2 = new ManualResetEvent(false);

                // Create a two clients to connect with the Boggle Server.
                TcpClient TestClient1 = new TcpClient("localhost", 2000);
                TcpClient TestClient2 = new TcpClient("localhost", 2000);

                // Create a client socket and then a client string socket.
                Socket ClientSocket1 = TestClient1.Client;
                Socket ClientSocket2 = TestClient2.Client;
                StringSocket ClientSS1 = new StringSocket(ClientSocket1, new UTF8Encoding());
                StringSocket ClientSS2 = new StringSocket(ClientSocket2, new UTF8Encoding());

                try
                {
                    // Case 1: The user doesn't begin with the PLAY command.
                    ClientSS1.BeginSend("Illegal Client1\n", PlayCallback1, 1);
                    ClientSS2.BeginSend("Illegal Client2\n", PlayCallback2, 2);

                    // When the connection between the server and clients is established,
                    // the server expects the command PLAY @. But in this case we didn't
                    // send that command, so we should expect an IGNORING reply from the
                    // server.
                    ClientSS1.BeginReceive(CompletedReceive1, 1);
                    ClientSS2.BeginReceive(CompletedReceive2, 2);

                    // Assert that the server sent back the correct commands after the two clients
                    // connected.
                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual("IGNORING Illegal Client1", s1);
                    Assert.AreEqual(1, p1);
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");
                    Assert.AreEqual("IGNORING Illegal Client2", s2);
                    Assert.AreEqual(2, p2);
                }
                finally
                {
                    ClientSS1.Close();
                    ClientSS2.Close();
                }
            }
开发者ID:jon-whit,项目名称:PS8,代码行数:48,代码来源:BoggleServerTests.cs

示例5: TestClientDisconnect1

            /// <summary>
            /// 
            /// </summary>
            public void TestClientDisconnect1()
            {
                // If at any point during a game a client disconnects or becomes inaccessible, the
                // game ends. The server should send the command "TERMINATED" to the surviving client
                // and then close the socket.

                //First test: disconnection while in a game
                // This will coordinate communication between the threads of the test cases
                mre1 = new ManualResetEvent(false);
                mre2 = new ManualResetEvent(false);
                mre3 = new ManualResetEvent(false);
                mre4 = new ManualResetEvent(false);

                // Create a two clients to connect with the Boggle Server.
                TcpClient TestClient1 = new TcpClient("localhost", 2000);
                TcpClient TestClient2 = new TcpClient("localhost", 2000);

                // Create a client socket and then a client string socket.
                Socket ClientSocket1 = TestClient1.Client;
                Socket ClientSocket2 = TestClient2.Client;
                StringSocket ClientSS1 = new StringSocket(ClientSocket1, new UTF8Encoding());
                StringSocket ClientSS2 = new StringSocket(ClientSocket2, new UTF8Encoding());

                try
                {
                    // Now our client needs to send the command PLAY @ and the server will receive it.
                    ClientSS1.BeginSend("PLAY Client1\n", PlayCallback1, 1);
                    ClientSS2.BeginSend("PLAY Client2\n", PlayCallback2, 2);

                    // When a connection has been established, the client sends a command to
                    // the server. The command is "PLAY @", where @ is the name of the player.
                    // Assert that the server receives the command PLAY @
                    ClientSS1.BeginReceive(CompletedReceive1, 1);
                    ClientSS2.BeginReceive(CompletedReceive2, 2);

                    // Assert that the server sent back the correct commands after the two clients
                    // connected.
                    string ExpectedExpression = @"^(START) [a-zA-Z]{16} \d+ [a-zA-Z1-9]+";
                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.IsTrue(Regex.IsMatch(s1, ExpectedExpression));
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");
                    Assert.IsTrue(Regex.IsMatch(s2, ExpectedExpression));

                    // Now that the game has started, we need to assert that we are receiving the
                    // Command when one client disconnects.
                    ClientSS1.BeginReceive(CompletedReceive3, 3);
                    ClientSS1.BeginReceive(CompletedReceive4, 4);
                    ClientSS2.Close();

                    Assert.AreEqual(true, mre3.WaitOne(timeout), "Timed out waiting 3");
                    Assert.AreEqual("TERMINATED", s3);
                    Assert.AreEqual(3, p3);

                    Assert.AreEqual(true, mre4.WaitOne(timeout), "Timed out waiting 4");
                    Assert.AreEqual(null, s4);
                    Assert.AreEqual(4, p4);
                }
                finally
                {
                    ClientSS1.Close();
                    ClientSS2.Close();
                }
            }
开发者ID:jon-whit,项目名称:PS8,代码行数:66,代码来源:BoggleServerTests.cs

示例6: TestWordCommand2

            public void TestWordCommand2()
            {
                // Test for words that are played that are less than 3 characters in
                // length. Assert that the scores didn't change.

                // This will coordinate communication between the threads of the test cases
                mre1 = new ManualResetEvent(false);
                mre2 = new ManualResetEvent(false);

                // Create a two clients to connect with the Boggle Server.
                TcpClient TestClient1 = new TcpClient("localhost", 2000);
                TcpClient TestClient2 = new TcpClient("localhost", 2000);

                // Create a client socket and then a client StringSocket.
                Socket ClientSocket1 = TestClient1.Client;
                Socket ClientSocket2 = TestClient2.Client;
                StringSocket ClientSS1 = new StringSocket(ClientSocket1, new UTF8Encoding());
                StringSocket ClientSS2 = new StringSocket(ClientSocket2, new UTF8Encoding());

                try
                {
                    // Connect two clients together to play Boggle.
                    ClientSS1.BeginSend("PLAY Client1\n", (e, o) => { }, null);
                    ClientSS2.BeginSend("PLAY Client2\n", (e, o) => { }, null);

                    ClientSS1.BeginReceive(CompletedReceive1, 1);
                    ClientSS2.BeginReceive(CompletedReceive2, 3);
                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");

                    // Get all of the legal words from the gameboard for these two players.
                    HashSet<string> LegalWords = FindXLetterWords(GameboardString, 3);

                    // Send a legal word and a word with less than 3 characters. The score
                    // shouldn't change.
                    ClientSS1.BeginSend("WORD " + LegalWords.ElementAt(0) + "\n", (e, o) => { }, null);
                    ClientSS1.BeginSend("WORD xx\n", (e, o) => { }, null);
                    ClientSS1.BeginSend("WORD " + LegalWords.ElementAt(1) + "\n", (e, o) => { }, null);

                    mre1 = new ManualResetEvent(false);
                    mre2 = new ManualResetEvent(false);

                    ClientSS1.BeginReceive(CompletedReceive1, 2);
                    ClientSS1.BeginReceive(CompletedReceive2, 2);

                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual("SCORE 1 0", s1);
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 3");
                    Assert.AreEqual("SCORE 2 0", s2);

                    mre1 = new ManualResetEvent(false);
                    mre2 = new ManualResetEvent(false);

                    ClientSS2.BeginReceive(CompletedReceive1, 3);
                    ClientSS2.BeginReceive(CompletedReceive2, 3);

                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual("SCORE 0 1", s1);
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 3");
                    Assert.AreEqual("SCORE 0 2", s2);
                }
                finally
                {
                    ClientSS1.Close();
                    ClientSS2.Close();
                }
            }
开发者ID:jon-whit,项目名称:PS8,代码行数:67,代码来源:BoggleServerTests.cs

示例7: TestWordCommand1

            public void TestWordCommand1()
            {
                // Test a single legal word played by one of the two Boggle players and
                // assert that the score incremented appropriately.

                // This will coordinate communication between the threads of the test cases
                mre1 = new ManualResetEvent(false);
                mre2 = new ManualResetEvent(false);

                // Create a two clients to connect with the Boggle Server.
                TcpClient TestClient1 = new TcpClient("localhost", 2000);
                TcpClient TestClient2 = new TcpClient("localhost", 2000);

                // Create a client socket and then a client StringSocket.
                Socket ClientSocket1 = TestClient1.Client;
                Socket ClientSocket2 = TestClient2.Client;
                StringSocket ClientSS1 = new StringSocket(ClientSocket1, new UTF8Encoding());
                StringSocket ClientSS2 = new StringSocket(ClientSocket2, new UTF8Encoding());

                try
                {
                    // Connect two clients together to play Boggle.
                    ClientSS1.BeginSend("PLAY Client1\n", (e, o) => { }, null);
                    ClientSS2.BeginSend("PLAY Client2\n", (e, o) => { }, null);

                    ClientSS1.BeginReceive(CompletedReceive1, 1);
                    ClientSS2.BeginReceive(CompletedReceive2, 3);
                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");

                    // Get all of the legal words from the gameboard for these two players.
                    HashSet<string> LegalWords = FindLegalWords(GameboardString);

                    ClientSS1.BeginSend("WORD " + LegalWords.ElementAt(0) + "\n", (e, o) => { }, null);
                    mre1 = new ManualResetEvent(false);
                    mre2 = new ManualResetEvent(false);

                    ClientSS1.BeginReceive(CompletedReceive1, 2);
                    ClientSS2.BeginReceive(CompletedReceive2, 3);

                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual("SCORE 1 0", s1);
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");
                    Assert.AreEqual("SCORE 0 1", s2);
                }
                finally
                {
                    ClientSS1.Close();
                    ClientSS2.Close();
                }
            }
开发者ID:jon-whit,项目名称:PS8,代码行数:51,代码来源:BoggleServerTests.cs

示例8: PairClients

            /// <summary>
            /// Test used to determine if two Boggle clients are being paired together properly. 
            /// Two clients are paired together properly if they receive the command START $ # @, 
            /// where $ are the characters that make up the board, # is the game time, and @ is 
            /// the opponents name.
            /// </summary>
            public void PairClients()
            {
                // This will coordinate communication between the threads of the test cases
                mre1 = new ManualResetEvent(false);
                mre2 = new ManualResetEvent(false);

                // Create a two clients to connect with the Boggle Server.
                TcpClient TestClient1 = new TcpClient("localhost", 2000);
                TcpClient TestClient2 = new TcpClient("localhost", 2000);

                // Create a client socket and then a client string socket.
                Socket ClientSocket1 = TestClient1.Client;
                Socket ClientSocket2 = TestClient2.Client;
                StringSocket ClientSS1 = new StringSocket(ClientSocket1, new UTF8Encoding());
                StringSocket ClientSS2 = new StringSocket(ClientSocket2, new UTF8Encoding());

                try
                {
                    // Now our client needs to send the command PLAY @ and the server will receive it.
                    ClientSS1.BeginSend("PLAY Client1\n", PlayCallback1, 1);
                    ClientSS2.BeginSend("PLAY Client2\n", PlayCallback2, 2);

                    // When a connection has been established, the client sends a command to
                    // the server. The command is "PLAY @", where @ is the name of the player.
                    // Assert that the server receives the command PLAY @
                    ClientSS1.BeginReceive(CompletedReceive1, 1);
                    ClientSS2.BeginReceive(CompletedReceive2, 2);

                    // Assert that the server sent back the correct commands after the two clients
                    // connected.
                    string ExpectedExpression = @"^(START) [a-zA-Z]{16} \d+ [a-zA-Z1-9]+";
                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.IsTrue(Regex.IsMatch(s1, ExpectedExpression));
                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");
                    Assert.IsTrue(Regex.IsMatch(s2, ExpectedExpression));
                }
                finally
                {
                    ClientSS1.Close();
                    ClientSS2.Close();
                }
            }
开发者ID:jon-whit,项目名称:PS8,代码行数:48,代码来源:BoggleServerTests.cs

示例9: registerUserAsAdmin

        /// <summary>
        /// Registers userName in server. Guarantees client username registration. Used if register fails.
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="port"></param>
        /// <param name="serverIP"></param>
        /// <param name="e"></param>
        public static void registerUserAsAdmin(string userName, string spreadsheet, int port, IPAddress serverIP, Encoding e)
        {
            //Connecting client to server and establishing a socket
            TcpClient client = new TcpClient();
            client.Connect(serverIP, port);
            StringSocket socket = new StringSocket(client.Client, e);

            //Register userName using sysadmin workaround
            socket.BeginSend("connect sysadmin " + spreadsheet + "\n", (ee, pp) => { }, null);
            socket.BeginSend("register " + userName + "\n", (ee, pp) => { }, null);
            socket.Close();
            socket = null;
        }
开发者ID:alexanderson2209,项目名称:Spreadsheet-Suite,代码行数:20,代码来源:Communicator.cs


注:本文中的CustomNetworking.StringSocket.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。