zoukankan      html  css  js  c++  java
  • 网络游戏_客户端

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Net.Sockets;
    using System.Net;

    namespace TCP客户端
    {
        class Program
        {
            static void Main(string[] args)
            {
                Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                clientSocket.Connect(new IPEndPoint(IPAddress.Parse("192.168.43.231"), 7788));
                //接收消息
                byte[] data = new byte[1024];
                int count= clientSocket.Receive(data);
                string message = Encoding.UTF8.GetString(data, 0, count);
                Console.WriteLine(message);
                //发送消息
                while (true)
                {
                    string messageSend = Console.ReadLine();    
                    //Console.Write(messageSend);
                    clientSocket.Send(Encoding.UTF8.GetBytes(messageSend));
                    if (messageSend == "c")
                    {
                        clientSocket.Close();
                        return;
                    }
                    clientSocket.Send(Encoding.UTF8.GetBytes(messageSend));

                }


                Console.ReadKey();
                clientSocket.Close();
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace TCP客户端
    {
        class Message
        {
            public static byte[] GetBytes(string data)
            {
                byte[] dataBytes = Encoding.UTF8.GetBytes(data);
                int dataLength = dataBytes.Length;
                byte[] lengthBytes = BitConverter.GetBytes(dataLength);
                byte[] newBytes = lengthBytes.Concat(dataBytes).ToArray();
                return newBytes;
            }
        }
    }

  • 相关阅读:
    2-sat问题,输出方案,几种方法(赵爽的论文染色解法+其完全改进版)浅析 / POJ3683
    hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。
    最小费用最大流粗解 poj2516
    hdu3078 建层次树+在线LCA算法+排序
    hdu 3594 Cactus /uva 10510 仙人掌图判定
    有向图最小路径覆盖方法浅析、证明 //hdu 3861
    hdu 1827 有向图缩点看度数
    条件转化,2-sat BZOJ 1997
    2-sat基础题 BZOJ 1823
    2-sat 分类讨论 UVALIVE 3713
  • 原文地址:https://www.cnblogs.com/shirln/p/7874427.html
Copyright © 2011-2022 走看看