消息测试

    //服务器端

            int port = 1433;

            string host = "10.252.21.8";

 

 

            IPAddress ip = IPAddress.Parse(host);

            IPEndPoint ipe = new IPEndPoint(ip, port);

 

            Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            clientSocket.Connect(ipe);

 

            //send message

            string sendStr = "send to server : hello,ni hao";

            byte[] sendBytes = Encoding.ASCII.GetBytes(sendStr);

            clientSocket.Send(sendBytes);

 

            //receive message

            string recStr = "";

            byte[] recBytes = new byte[4096];

            int bytes = clientSocket.Receive(recBytes, recBytes.Length, 0);

            recStr += Encoding.ASCII.GetString(recBytes, 0, bytes);

 

            textBox2.Text=recStr;

            clientSocket.Close();

posted @ 2018-01-15 10:43  辛新欣  阅读(140)  评论(0)    收藏  举报