/// <summary> /// 监听随机端口 /// 端口范围 5001-65535 /// </summary> /// <param name="ip"></param> /// <param name="action"> /// 接收到信息的操作 /// </param> /// <param name="started">成功监听端口时执行</param> /// <returns></returns> /// <exception cref="SocketException">Socket异常</exception> public static void Listen(string ip, Action <NetworkStream> action, Action <int> started) { Tcp.Listen(ip, (stream) => { action(stream); return(true); }, started); }
/// <summary> /// 监听 /// </summary> /// <param name="ip"></param> /// <param name="port"></param> /// <param name="action">接收到信息的操作</param> /// <returns></returns> /// <exception cref="SocketException">Socket异常</exception> public static void Listen(string ip, int port, Action <NetworkStream> action) { Tcp.Listen(ip, port, (stream) => { action(stream); return(true); }, null); }