zoukankan      html  css  js  c++  java
  • 网络编程01

    //服务端
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    
    namespace learn
    {
        class Program
        {
            const int portNo = 500;
    
            static void Main(string[] args)
            {
                IPAddress localAdd = IPAddress.Parse("127.0.0.1");
    
                TcpListener listener = new TcpListener(localAdd, portNo);
                listener.Start();
    
                TcpClient tcpClient = listener.AcceptTcpClient();
    
                NetworkStream ms = tcpClient.GetStream();
                byte[] data = new byte[tcpClient.ReceiveBufferSize];
    
                int numBytesRead = ms.Read(data, 0,System.Convert.ToInt32(tcpClient.ReceiveBufferSize));
    
                Console.WriteLine("Receiced:" + Encoding.ASCII.GetString(data, 0, numBytesRead));
                Console.ReadLine();
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net.Sockets;
    
    namespace Client_CS
    {
        class Program
        {
            const int portNo = 500;
            static void Main(string[] args)
            {
                TcpClient tcpclient = new TcpClient();
    
                tcpclient.Connect("127.0.0.1", portNo);
    
                NetworkStream ns = tcpclient.GetStream();
                byte[] data = Encoding.ASCII.GetBytes("Hello");
    
                ns.Write(data, 0, data.Length);
            }
        }
    }
  • 相关阅读:
    LeetCode70.爬楼梯
    LeetCode9.回文数
    LeetCode8.字符串转整数(atoi)
    LeetCode7.反转整数
    Docker深入浅出3-镜像管理
    Docker深入浅出3-容器管理
    Docker深入浅出2
    Docker深入浅出1
    Docker启动mysql的坑2
    各种常见兼容代码
  • 原文地址:https://www.cnblogs.com/softimagewht/p/4568912.html
Copyright © 2011-2022 走看看