ipendpointsample.cs

来自「visual c# 网络编程技术与实践实例包括几个源码」· CS 代码 · 共 25 行

CS
25
字号
//IPEndPointSample.cs
using System;
using System.Net;
class IPEndPointSample
{
    public static void Main()
    {
        IPAddress newaddress = IPAddress.Parse("192.168.1.1");
        //创建IPEndPoint实例
        IPEndPoint ex = new IPEndPoint(newaddress, 8000);
        Console.WriteLine("The IPEndPoint is:{0}", ex.ToString());
        Console.WriteLine("The AddressFamily is:{0}", ex.AddressFamily);
        Console.WriteLine("The Address is:{0},and the port is:{1}", ex.Address, ex.Port);
        Console.WriteLine("The Min Port Number is:{0}", IPEndPoint.MinPort);
        Console.WriteLine("The Max Port Number is:{0}", IPEndPoint.MaxPort);
        //用port属性单独改变IPEndPoint对象的端口值
        ex.Port = 80;
        Console.WriteLine("The changed IPEndPoint vaule is:{0}", ex.ToString());
        //存储IPEdnPoint实例
        SocketAddress sa = ex.Serialize();
        Console.WriteLine("The Socketaddress is:{0}", sa.ToString());
        Console.ReadLine();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?