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


C# TcpClient.Send方法代码示例

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


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

示例1: HandleMessage

        private void HandleMessage(string fullMessage, int code, TcpClient client, ServerWindow console)
        {
            string response = null;
            if (code == 302)
            {
                response = Protocol.GetClientResponse(fullMessage);
            }

            switch (code)
            {
                case 300:
                    client.Send(Protocol.GetResponseFromCode(404));
                    console.Log("Client sent 300 Response, but no question was asked. 404 No Question sent.");
                    break;
                case 301:
                    Server.RemoveClient(_username);
                    Server.SendMessage(string.Format("{0} left the chat.", _username), "Server");
                    console.Log("Client sent 301 Disconnecting. Client removed from list, closing resources.");
                    client.Close();
                    Thread.CurrentThread.Abort();
                    break;
                case 302:
                    new Thread(new ParameterizedThreadStart((tcpClient) =>
                    {
                        string respondToClient = this.Parse302Message(response);
                        TcpClient castedClient = (TcpClient)tcpClient;
                        Thread.Sleep(60);
                        castedClient.Send(respondToClient);
                    })).Start(client);
                    break;
            }
        }
开发者ID:ArtOfCode-,项目名称:ChatMessenger,代码行数:32,代码来源:ServerCommunicationThread.cs

示例2: Program

        public Program()
        {
            List<string> list = null;

            Socket _Socket = new TcpClient(host, 80).Client;
            _Socket.Send(File.ReadAllBytes("1 Sended.html"));
            NetworkStream _NetworkStream = new NetworkStream(_Socket);
            byte[] _bytes = Http.ReadHttp(_NetworkStream);
            string received = _bytes.ToStr().Save();
            _Socket.Close();
            MatchCollection _MatchCollection = Regex.Matches(received, @"<script>var b='(\w+)';document\.write", RegexOptions.IgnoreCase);
            list = new List<string>();

            foreach (Match m in _MatchCollection)
            {
                string page = m.Groups[1].Value;
                if (!list.Contains(page)) list.Add(page);
            }
            File.WriteAllLines("list.txt", list.ToArray());

            ("listcount;" + list.Count).Trace();
            for (int i = 0; i < list.Count; i++)
            {
                string page = list[0];
                list.RemoveAt(0);
                list.Add(page);
                File.WriteAllLines("list.txt", list.ToArray());
                try
                {
                    Send2(page);
                    //Thread.Sleep(60000 * 5);
                }
                catch (ExceptionA e) { Trace.WriteLine(e.Message); }
            }            
        }
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:35,代码来源:Program.cs

示例3: HandleMessage

        private void HandleMessage(string fullMessage, int code, TcpClient client, ServerWindow console)
        {
            string response = null;
            if (code == 302)
            {
                response = Protocol.GetClientResponse(fullMessage);
            }

            switch (code)
            {
                case 300:
                    client.Send(Protocol.GetResponseFromCode(404));
                    console.Log("Client sent 300 Response, but no question was asked. 404 No Question sent.");
                    break;
                case 301:
                    Server.RemoveClient(_username);
                    console.Log("Client sent 301 Disconnecting. Client removed from list, closing resources.");
                    client.Close();
                    Thread.CurrentThread.Abort();
                    break;
                case 302:
                    Server.SendMessage(string.Join("\n", response), _username);
                    new Thread(new ParameterizedThreadStart((tcpClient) =>
                    {
                        // Delay stops two messages being received at the same time and running together
                        Thread.Sleep(60);
                        TcpClient castedClient = (TcpClient)tcpClient;
                        castedClient.Send(Protocol.GetResponseFromCode(201));
                    })).Start(client);
                    break;
            }
        }
开发者ID:martijnhoekstra,项目名称:ChatMessenger,代码行数:32,代码来源:ServerCommunicationThread.cs

示例4: Connect

 private Socket Connect()
 {
     while (true)
         try
         {
             Socket _Socket = new TcpClient(host, port).Client;
             string s = Res.get.Replace("_host_", host + ":" + port).Replace("_page_", page);
             _Socket.Send(s);
             _NetworkStream = new NetworkStream(_Socket);
             _NetworkStream.ReadTimeout = 40000;
             string s2 = _NetworkStream.Cut("\r\n\r\n").ToStr();
             name = Regex.Match(s2, "icy-name:(.+)\r").Groups[1].Value;
             blocksize = int.Parse(Regex.Match(s2, @"icy-metaint:(.+)\b").Groups[1].Value);
             return _Socket;
         }
         catch { }
 }
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:17,代码来源:Program.cs

示例5: SendTo

        /// <summary>
        /// Send buffer to one client (Request)
        /// </summary>
        /// <param name="buffer">Buffer to send</param>
        /// <param name="client">Client</param>
        /// <returns>Success</returns>
        public bool SendTo(byte[] buffer, TcpClient client)
        {
            try
            {
                byte[] b = eUtils.GetBuffer(buffer);
                client.Send(b);

                DebugMessage("Buffer sent successfully.");

                return true;
            }
            catch (Exception ex)
            {
                DebugMessage("Failed to send buffer : " + ex.Message);
                return false;
            }
        }
开发者ID:EdgeKiller,项目名称:eNetwork2,代码行数:23,代码来源:eServer.cs

示例6: StartTor

 public static void StartTor()
 {
     if ((from p in Process.GetProcesses() where p.ProcessName == "tor" select p).FirstOrDefault() == null)
         Process.Start(_Tor);
     Socket _Socket = new TcpClient("localhost", 9051).Client;
     _Socket.Send("AUTHENTICATE \"er54s4\"\r\n");
     while (true)
     {
         _Socket.Send("getinfo stream-status\r\n");
         string s= _Socket.ReceiveText();
         StringBuilder _StringBuilder = new StringBuilder();
         foreach (Match m in Regex.Matches(s, @"\d\d?\d? (\w+ \d\d?\d?) [\d.]+:\d\d?\d?"))
         {
             _StringBuilder.Append(m.Groups[1].Value+",");
         }
         Title = _StringBuilder.ToString();
         Thread.Sleep(100);
     }
 }
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:19,代码来源:Program.cs

示例7: tcpServer_OnReceiveData

        /// <summary>
        /// When server receive data from a client
        /// </summary>
        /// <param name="tcpClient">TcpClient</param>
        /// <param name="packet">Packet</param>
        private void tcpServer_OnReceiveData(TcpClient tcpClient, Packet packet)
        {
            //Log(packet.ID);
            switch (packet.ID)
            {
                case 1:
                    if (ListHelper.ArrayContains(tcpClient, players))
                    {
                        Player tempPlayer = ListHelper.GetPlayerFromTcpClient(tcpClient, players);
                        tempPlayer.TcpClient.Send(new Packet(3, new byte[1] { tempPlayer.Slot }).ToByteArray());
                    }
                    break;

                case 4:
                    tcpServer.SendToAll(packet);
                    break;
                case 68:
                    //tcpServer.SendToAll(packet);
                    break;
                case 16:
                    tcpServer.SendToAll(packet);
                    break;
                case 42:
                    tcpServer.SendToAll(packet);
                    break;
                case 50:
                    tcpServer.SendToAll(packet);
                    break;
                case 5:
                    tcpServer.SendToAll(packet);
                    break;
                case 6:
                    tcpClient.Send(new Packet(7, world.ToByteArray()).ToByteArray());
                    break;

                default:
                    Log(Config.Lang.GetString("unknownPacketReceived") + " : " + packet.ID);
                    break;

            }
        }
开发者ID:TerrariaSharp,项目名称:TerrariaSharpServer,代码行数:46,代码来源:TerrariaServer.cs

示例8: SendTo

        public bool SendTo(byte[] buffer, TcpClient client)
        {
            try
            {
                client.Send(buffer);

                Logger.Debug("Buffer sent successfully.", DebugLevel);

                return true;
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to send buffer : " + ex.Message, DebugLevel);
                return false;
            }
        }
开发者ID:EdgeKiller,项目名称:eNetwork3,代码行数:16,代码来源:eServer.cs


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