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


C# CustomNetworking.StringSocket类代码示例

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


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

示例1: Connect

        /// <summary>
        /// Connect to the server at the given hostname and port and with the given name of username and
        /// password.
        /// </summary>
        public bool Connect(String hostname, int port, String password)
        {
            try
            {
                TcpClient client;
                //Case 1: Using IP
                IPAddress address;
                if (IPAddress.TryParse(hostname, out address))
                {
                    client = new TcpClient();
                    client.Connect(address, port);
                }
                else
                {
                    //Case 2: Using DNS
                    client = new TcpClient(hostname, port);
                }

                socket = new StringSocket(client.Client, UTF8Encoding.Default);
                //PASSWORD[esc]password\n
                char esc = (char)27;
                socket.BeginSend("PASSWORD" + esc + password + "\n", (e, p) => { }, null);
                socket.BeginReceive(LineReceived, null);

                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:unaveed,项目名称:Spreadsheet,代码行数:35,代码来源:Client.cs

示例2: Connect

 public void Connect(string hostname, int port, string clientPassword)
 {
     // initial connection to the server
     if (clientSSocket == null)
     {
         password = clientPassword;
         try
         {
             TcpClient client = new TcpClient(hostname, port);
             clientSSocket = new StringSocket(client.Client, UTF8Encoding.Default);
             clientSSocket.BeginSend("PASSWORD" + "\\e" + password + "\n", (ex, p) => { }, null);
             clientSSocket.BeginReceive(LineReceived, null);
         }
         catch (SocketException e)
         {
             Console.WriteLine(e.Message);
         }
     }
     // not sure if this part is necessary?
     else
     {
         //clientSSocket.Close(); we don't want to close the socket unless the client is disconnecting
         TcpClient client = new TcpClient(hostname, port);
         clientSSocket = new StringSocket(client.Client, UTF8Encoding.Default);
         clientSSocket.BeginSend("PASSWORD"+ "\\e" + password + "\n", (ex, p) => { }, null);
         clientSSocket.BeginReceive(LineReceived, null);
     }
 }
开发者ID:hodgeskyjon,项目名称:3505_Spring_Project,代码行数:28,代码来源:SpreadsheetClientModel.cs

示例3: TestBasicWord

        public void TestBasicWord()
        {
            TcpListener server = null;
            TcpClient client1 = null;
            TcpClient client2 = null;

            server = new TcpListener(IPAddress.Any, 4042);
            server.Start();
            client1 = new TcpClient("localhost", 4042);
            client2 = new TcpClient("localhost", 4042);

            Socket serverSocket = server.AcceptSocket();

            Socket client1Socket = client1.Client;
            Socket client2Socket = client2.Client;

            StringSocket sendSocket = new StringSocket(serverSocket, new UTF8Encoding());
            StringSocket player1Socket = new StringSocket(client1Socket, new UTF8Encoding());
            StringSocket player2Socket = new StringSocket(client2Socket, new UTF8Encoding());

            BoggleServer.BoggleServer.Player player1 = new BoggleServer.BoggleServer.Player("ryan", player1Socket);
            BoggleServer.BoggleServer.Player player2 = new BoggleServer.BoggleServer.Player("ryan2", player2Socket);

            BoggleServer.BoggleServer.Match match = new BoggleServer.BoggleServer.Match(
                player1, player2, 60, new HashSet<string>(System.IO.File.ReadAllLines(@"..\..\..\Resources\Dictionary.txt")), "horstoaeaggdpple");

            match.ReceivedPlayer1Data("word horse", null, player1Socket);
            Assert.AreEqual(2, player1.Score);
            Assert.IsTrue(player1.UniqueLegalWords.Contains("HORSE"));
        }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:30,代码来源:BoggleServerTest.cs

示例4: User

        public User(string _name, StringSocket _socket)
        {
            Name = _name;
            socket = _socket;
            Terminated = false;

            socket.BeginReceive(LineReceivedFromUser, socket);
        }
开发者ID:unaveed,项目名称:Spreadsheet,代码行数:8,代码来源:User.cs

示例5: Connect

        /// <summary>
        /// Connect to the server at the given hostname and port and with the given name.
        /// </summary>
        public void Connect(string hostname, int port)
        {
            // Connect or throw exception
            _client = new TcpClient(hostname, port);

            // Create a StringSocket for communicating with the server.
            _stringSocket = new StringSocket(_client.Client, UTF8Encoding.Default);           
        }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:11,代码来源:BoggleClientModel.cs

示例6: Connect

 //make sure the client isn't already connected
 //then connect
 public void Connect(int port, string hostName)
 {
     if (ss == null)
     {
         TcpClient client = new TcpClient(hostName, port);
         ss = new StringSocket(client.Client, UTF8Encoding.Default);
         IsConnected = true;
     }
 }
开发者ID:ryoia,项目名称:BoggleGames,代码行数:11,代码来源:BoggleClientModel.cs

示例7: Connect

 /// <summary>
 /// connects on the given port and ip
 /// </summary>
 /// <param name="port"></param>
 /// <param name="ip"></param>
 public void Connect(int port, string ip)
 {
     if (socket == null)
     {
         TcpClient client = new TcpClient(ip, port);
         socket = new StringSocket(client.Client, UTF8Encoding.Default);
         state = State.name;
         socket.BeginReceive(LineReceived, null);
     }
 }
开发者ID:jiiehe,项目名称:cs3500,代码行数:15,代码来源:ClientModel.cs

示例8: ConnectionReceived

 /// <summary>
 /// This callback method is called when a connection has been received.
 /// </summary>
 private void ConnectionReceived(IAsyncResult ar)
 {
     Socket socket = server.EndAcceptSocket(ar);
     StringSocket ss = new StringSocket(socket, UTF8Encoding.Default);
     
     // Set the StringSocket to listen for a name from the client.
     ss.BeginReceive(GetReceived, ss);
     
     // Set the server to listen for another connection.
     server.BeginAcceptSocket(ConnectionReceived, null);
 }
开发者ID:jimibue,项目名称:cs3505,代码行数:14,代码来源:WebServer.cs

示例9: Connect

 /// <summary>
 /// Connect to the server at the given hostname and port and with the give name.
 /// </summary>
 public void Connect(string hostname, String name)
 {
     if (socket == null)
     {
         playerName = name;
         TcpClient client = new TcpClient(hostname, 2000);
         socket = new StringSocket(client.Client, UTF8Encoding.Default);
         socket.BeginSend("PLAY " + name + "\n", (e, p) => { }, null);
         socket.BeginReceive(LineReceived, null);
     }
 }
开发者ID:joesturz,项目名称:Boggle,代码行数:14,代码来源:Class1.cs

示例10: Connect

        /// <summary>
        /// Connect to the server at the given hostname and port and with the give name.
        /// </summary>
        public void Connect(string hostname, int port, String name)
        {
            if (socket == null||!validName )
            {
                if (name.StartsWith("PLAY ") && name.Substring(5).Trim().Length > 0)
                    validName = true;
                
                TcpClient client = new TcpClient(hostname, port);
                socket = new StringSocket(client.Client, UTF8Encoding.Default);

                socket.BeginSend(name + "\n", (e, p) => { }, null);
                socket.BeginReceive(LineReceived, null);
            }
        }
开发者ID:jimibue,项目名称:cs3505,代码行数:17,代码来源:BoggleClientModel.cs

示例11: Connect

        /// <summary>
        /// Connect to the server at the given hostname and port, with the given name.
        /// </summary>
        public void Connect(String hostname, int port, String name)
        {
            if (socket == null)
            {
                TcpClient client = new TcpClient(hostname, port);
                socket = new StringSocket(client.Client, UTF8Encoding.Default);

                this.name = name;
                this.hostname = hostname;

                socket.BeginSend("PLAY " + name + "\n", (e, p) => { }, null);
                socket.BeginReceive(LineReceived, null);
            }
        }
开发者ID:jimibue,项目名称:cs3505,代码行数:17,代码来源:BoggleClientModel.cs

示例12: Main

        static void Main(string[] args)
        {
            //new server
            TcpListener server = new TcpListener(IPAddress.Any, 4010);

            server.Start();
            //blocks until user connects
            Socket serverSocket = server.AcceptSocket();
            Console.WriteLine("hey");

            // Wrap the two ends of the connection into StringSockets
            StringSocket sendSocket = new StringSocket(serverSocket, new UTF8Encoding());
            sendSocket.BeginSend("hi", (e, o) => { }, null);
            Console.ReadLine();
        }
开发者ID:jiiehe,项目名称:cs3500,代码行数:15,代码来源:Program.cs

示例13: Connect

 /// <summary>
 /// Connect to the server at the given hostname and port and with the give name.
 /// </summary>
 public void Connect(string IPAddress, String name)
 {
     if (socket == null)
     {
         try
         {
             TcpClient client = new TcpClient(IPAddress, 2000);
             socket = new StringSocket(client.Client, UTF8Encoding.Default);
             socket.BeginSend("PLAY " + name + "\n", (e, p) => { }, null);
             socket.BeginReceive(LineReceived, null);
         }
         catch (Exception e)
         {
             //no such host event
             noSuchHostEvent(e.Message);
         }
     }
 }
开发者ID:matelau,项目名称:Boggle-Game-PS10,代码行数:21,代码来源:BoggleClientModel.cs

示例14: Connect

 /// <summary>
 /// Takes a string representing the IP Address of the server, an int with the port number and the players name.
 /// It then connects to the server and sends the play message with the players name.
 /// </summary>
 public void Connect(String password)
 {
     if (socket == null || !socket.Connected())
     {
         // Tries to connect to the server and then send the play message
         try
         {
             TcpClient client = new TcpClient(IP, port);
             socket = new StringSocket(client.Client, UTF8Encoding.Default);
             socket.BeginSend(password, (e, p) => { }, null);
             socket.BeginReceive(LineReceived, null);
         }
         // If it is unable to connect it catches the exception and throws it on
         catch (SocketException e)
         {
             throw e;
         }
     }
 }
开发者ID:keivnlee,项目名称:Spreadsheet,代码行数:23,代码来源:Class1.cs

示例15: runGame

        public void runGame()
        {
            server = new BoggleServer.BoggleServer(2000, 10, "..\\..\\..\\dictionary", "AAAABBBBCCCCDDDD");
            player1 = new TcpClient("localhost", 2000);
            player2 = new TcpClient("localhost", 2000);
            Socket p1socket = player1.Client;
            Socket p2socket = player2.Client;
            p1 = new StringSocket(p1socket, new UTF8Encoding());
            p2 = new StringSocket(p2socket, new UTF8Encoding());
            p1.BeginSend("PLAY player1\n", (e, o) => { }, null);
            p2.BeginSend("PLAY player2\n", (e, o) => { }, null);
            mre = new ManualResetEvent(false);
            receivedWords = new List<string>();
            for (int i = 0; i < 20; i++)
            {
                p1.BeginReceive(callback, p1);
            }
            mre.WaitOne(1000);

            Assert.IsTrue(receivedWords.Contains("START AAAABBBBCCCCDDDD 10 PLAYER2"));
        }
开发者ID:ryoia,项目名称:BoggleGames,代码行数:21,代码来源:UnitTest1.cs


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