public void Connect(IPHostEndPoint remoteEndPoint, string[] Descriptions) { Socket SessionSocket = new Socket(remoteEndPoint.IPaddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (!remoteEndPoint.Port.HasValue) { throw new NullReferenceException("Port is null"); } try { SessionSocket.Connect(new IPEndPoint(remoteEndPoint.IPaddress, (int)remoteEndPoint.Port)); Check_ConnectOut_Connection(SessionSocket, Descriptions); } catch (Exception) { MessageSocketInformation temp = new MessageSocketInformation(this._InformationProperty.PrimaryID); temp.Description.Add("Connect Failed. Please check remote host."); _IMessageSocketSession.OnConnectFailed(temp.Info_ServerID, temp); } }
public void StartListenMessageSocket(IPHostEndPoint hostEndPoint) { if (hostEndPoint.IPaddress == null || !hostEndPoint.Port.HasValue) { throw new ArgumentNullException("hostEndPoint is null."); } if (_NetworkInfoUtility.IsUsedIPEndPoint((int)hostEndPoint.Port)) { throw new ArgumentException("Port: " + hostEndPoint.Port + " is used."); } if (_RecvSessionTask_Flag) { return; } this._LocalhostEndPoint = hostEndPoint; _RecvSessionTask_Flag = false; _RecvMessageSocketListener = new TcpListener(_LocalhostEndPoint.IPaddress, (int)_LocalhostEndPoint.Port); _RecvSessionTask = Task.Factory.StartNew(() => ExecutingRecvSessionTask(_RecvMessageSocketListener), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); }