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);
            }
        }
    }
  • 相关阅读:
    向 DataGridView 的行集合中添加行
    添加form窗口最大化最小化事件
    转义字符表
    键盘输入变简单了
    数字9X9的表格
    统计你输入的任意字符
    一个九九表
    用冒泡法排序
    学生会
    任意排序几个数
  • 原文地址:https://www.cnblogs.com/softimagewht/p/4568912.html
Copyright © 2011-2022 走看看