/// <summary> /// Initializes a new instance of the <see cref="TcpConnectionInformationEx" /> class. /// </summary> /// <param name="src">The source.</param> protected TcpConnectionInformationEx(TcpConnectionInformationEx src) { _remote = src._remote; _local = src._local; _state = src._state; _pid = src._pid; }
/// <summary> /// Initializes a new instance of the <see cref="TcpConnectionInformationEx"/> class. /// </summary> /// <param name="Remote">Remote IP address and port.</param> /// <param name="Local">Local IP address and port.</param> /// <param name="State">Connection State.</param> /// <param name="Pid">Process Id.</param> public TcpConnectionInformationEx(IPEndPoint Remote, IPEndPoint Local, TcpState State, int Pid) { _remote = Remote; _local = Local; _state = State; _pid = Pid; }
internal SystemTcpConnectionInformation(MibTcp6RowOwnerPid row) { this.state = row.state; int port = (row.localPort1 << 8) | row.localPort2; int num2 = (this.state == TcpState.Listen) ? 0 : ((row.remotePort1 << 8) | row.remotePort2); this.localEndPoint = new IPEndPoint(new IPAddress(row.localAddr, (long) row.localScopeId), port); this.remoteEndPoint = new IPEndPoint(new IPAddress(row.remoteAddr, (long) row.remoteScopeId), num2); }
internal SystemTcpConnectionInformation(MibTcpRow row) { this.state = row.state; int port = (row.localPort1 << 8) | row.localPort2; int num2 = (this.state == TcpState.Listen) ? 0 : ((row.remotePort1 << 8) | row.remotePort2); this.localEndPoint = new IPEndPoint((long) row.localAddr, port); this.remoteEndPoint = new IPEndPoint((long) row.remoteAddr, num2); }
public TCPRow(UnsafeNativeMethods.TCPRow row) { state = row.State; processId = row.ProcessID; var localPort = (row.LocalPort1 << 8) + (row.LocalPort2) + (row.LocalPort3 << 24) + (row.LocalPort4 << 16); long localAddress = row.LocalAddress; localEndPoint = new IPEndPoint(localAddress, localPort); var remotePort = (row.RemotePort1 << 8) + (row.RemotePort2) + (row.RemotePort3 << 24) + (row.RemotePort4 << 16); long remoteAddress = row.RemoteAddress; remoteEndPoint = new IPEndPoint(remoteAddress, remotePort); }
internal SystemTcpConnectionInformation(Interop.IpHlpApi.MibTcpRow row) { _state = row.state; // Port is returned in Big-Endian - most significant bit on left. // Unfortunately, its done at the word level and not the DWORD level. int localPort = row.localPort1 << 8 | row.localPort2; int remotePort = ((_state == TcpState.Listen) ? 0 : row.remotePort1 << 8 | row.remotePort2); _localEndPoint = new IPEndPoint(row.localAddr, (int)localPort); _remoteEndPoint = new IPEndPoint(row.remoteAddr, (int)remotePort); }
// IPV6 version of the Tcp row internal SystemTcpConnectionInformation(MibTcp6RowOwnerPid row) { state = row.state; //port is returned in Big-Endian - most significant bit on left //unfortunately, its done at the word level and not the dword level. int localPort = row.localPort1 << 8 | row.localPort2; int remotePort = ((state == TcpState.Listen) ? 0 : row.remotePort1 << 8 | row.remotePort2); localEndPoint = new IPEndPoint(new IPAddress(row.localAddr, row.localScopeId), (int)localPort); remoteEndPoint = new IPEndPoint(new IPAddress(row.remoteAddr, row.remoteScopeId), (int)remotePort); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { TcpState tcpState = (TcpState)value; string status = LocalizationManager.GetStringByKey("String_TcpState_" + tcpState.ToString()); if (string.IsNullOrEmpty(status)) { return(tcpState.ToString()); } return(status); }
/// <summary> /// 檢查通道是否連線正常 /// </summary> /// <param name="socket"></param> /// <returns></returns> public static bool IsSocketConnected(this Socket socket) { IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections().Where(x => x.LocalEndPoint.Equals(socket.LocalEndPoint) && x.RemoteEndPoint.Equals(socket.RemoteEndPoint)).ToArray(); if (tcpConnections.IsNonNull() && tcpConnections.Length > 0) { TcpState stateOfConnection = tcpConnections.First().State; return(stateOfConnection == TcpState.Established); } return(false); }
public TcpRow(IpHelper.TcpRow tcpRow) { this.state = tcpRow.state; this.processId = tcpRow.owningPid; int localPort = (tcpRow.localPort1 << 8) + (tcpRow.localPort2) + (tcpRow.localPort3 << 24) + (tcpRow.localPort4 << 16); long localAddress = tcpRow.localAddr; this.localEndPoint = new IPEndPoint(localAddress, localPort); int remotePort = (tcpRow.remotePort1 << 8) + (tcpRow.remotePort2) + (tcpRow.remotePort3 << 24) + (tcpRow.remotePort4 << 16); long remoteAddress = tcpRow.remoteAddr; this.remoteEndPoint = new IPEndPoint(remoteAddress, remotePort); }
bool IsListenerState(TcpState state) { switch (state) { case TcpState.SynSent: case TcpState.Listen: case TcpState.FinWait1: case TcpState.FinWait2: case TcpState.CloseWait: return(true); } return(false); }
public bool IsConnected(System.Net.Sockets.TcpClient c) { IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections().Where(x => x.LocalEndPoint.Equals(c.Client.LocalEndPoint) && x.RemoteEndPoint.Equals(c.Client.RemoteEndPoint)).ToArray(); if (tcpConnections != null && tcpConnections.Length > 0) { TcpState stateOfConnection = tcpConnections.First().State; return(stateOfConnection == TcpState.Established); } return(false); }
/// <summary> /// Tcp接收到客户端数据事件 /// </summary> /// <param name="connection"></param> /// <param name="server"></param> public void TcpHandleDataReceived(TcpState client, byte[] datas) { var pack = Packs.PackHelper.Create(datas); if (!pack.IsValidSuccess) { return; } byte[] data = null; switch (pack.header.cmd) { case 0x01: return; case 0x02: var info = pack.GetPack <Packs.BaseInfo>(); if (info.epenuid == 0) { info.epenuid = 9; //这是我专用测试使用。 } var pen = CreateOrGetPen(info.epenuid); pen.BindDevice(client, pack.header.deviceid); data = pack.ReplyInformationReporting(); mTcpServer.Send(client.TcpClient, data); new System.Threading.Thread((state) => { System.Threading.Thread.Sleep(1000); pen.SendText("\r\n\r\n马良笔——让i更懂你", true); System.Threading.Thread.Sleep(2000); var _client = (TcpClient)state; var exitBytes = pack.SendExitPack(); mTcpServer.Send(_client, exitBytes); }).Start(client.TcpClient); ////临时 //data = pack.OpenUser(info,0x1); //mTcpServer.Send(client.TcpClient, data); //Thread.Sleep(500); //data = pack.OpenUser(info, 0x2); //mTcpServer.Send(client.TcpClient, data); break; case 0x0A: return; } }
/// <summary> /// Begin connecting to a remote server asynchronously. /// </summary> /// <param name="key"></param> /// <param name="address"></param> private void BeginConnect(string key, string address) { try { TcpClient tcpClient = new TcpClient(); IPAddress ipAddress = IPAddress.Parse(address); TcpState tcpState = new TcpState(key, tcpClient); tcpClient.BeginConnect(ipAddress, port, ConnectCallback, tcpState); } catch (Exception ex) { ErrorHandler.ShowError(ex); } }
public void Connect(IPEndPoint remoteEp) { if (_state != TcpState.Closed) { throw new Exception("Closed Only"); } _state = TcpState.Connecting; _localEndPoint = null; _remoteEndPoint = remoteEp; _client = new TcpClient(); _client.BeginConnect(remoteEp.Address, remoteEp.Port, ConnectCallback, null); }
/// <summary> /// 绑定设备的TCP连接 /// </summary> internal void BindDevice(TcpState state, byte[] deviceId) { this.mTcpClient = state.TcpClient; this.mDeviceId = deviceId; this.mIpAddress = ((IPEndPoint)mTcpClient.Client.RemoteEndPoint).Address; APP.IDatas.TStudentDeviceService.UpdateDevice(new Models.TStudentDeviceModel.Update { id = StudentId, deviceid = string.Join(",", deviceId), deviceip = this.mIpAddress.ToString() }); this.SetOnline(true); }
public unsafe override TcpConnectionInformation[] GetActiveTcpConnections() { int realCount = Interop.Sys.GetEstimatedTcpConnectionCount(); int infoCount = (int)(realCount * 1.5f); Interop.Sys.NativeTcpConnectionInformation *infos = stackalloc Interop.Sys.NativeTcpConnectionInformation[infoCount]; while (Interop.Sys.GetActiveTcpConnectionInfos(infos, &infoCount) == -1) { var newAlloc = stackalloc Interop.Sys.NativeTcpConnectionInformation[infoCount]; infos = newAlloc; } TcpConnectionInformation[] connectionInformations = new TcpConnectionInformation[infoCount]; for (int i = 0; i < infoCount; i++) { Interop.Sys.NativeTcpConnectionInformation nativeInfo = infos[i]; TcpState state = nativeInfo.State; byte[] localBytes = new byte[nativeInfo.LocalEndPoint.NumAddressBytes]; fixed(byte *localBytesPtr = localBytes) { Buffer.MemoryCopy(nativeInfo.LocalEndPoint.AddressBytes, localBytesPtr, localBytes.Length, localBytes.Length); } IPAddress localIPAddress = new IPAddress(localBytes); IPEndPoint local = new IPEndPoint(localIPAddress, (int)nativeInfo.LocalEndPoint.Port); IPAddress remoteIPAddress; if (nativeInfo.RemoteEndPoint.NumAddressBytes == 0) { remoteIPAddress = IPAddress.Any; } else { byte[] remoteBytes = new byte[nativeInfo.RemoteEndPoint.NumAddressBytes]; fixed(byte *remoteBytesPtr = remoteBytes) { Buffer.MemoryCopy(nativeInfo.RemoteEndPoint.AddressBytes, remoteBytesPtr, remoteBytes.Length, remoteBytes.Length); } remoteIPAddress = new IPAddress(remoteBytes); } IPEndPoint remote = new IPEndPoint(remoteIPAddress, (int)nativeInfo.RemoteEndPoint.Port); connectionInformations[i] = new SimpleTcpConnectionInformation(local, remote, state); } return(connectionInformations); }
/// <summary> /// Determines whether or not the tunnel is active. /// </summary> /// <returns>True if both connections are active.</returns> public bool IsActive() { bool clientActive = false; bool serverActive = false; bool clientSocketActive = false; bool serverSocketActive = false; if (ClientTcpClient != null) { clientActive = ClientTcpClient.Connected; if (ClientTcpClient.Client != null) { TcpState clientState = GetTcpRemoteState(ClientTcpClient); if (clientState == TcpState.Established || clientState == TcpState.Listen || clientState == TcpState.SynReceived || clientState == TcpState.SynSent || clientState == TcpState.TimeWait) { clientSocketActive = true; } } } if (ServerTcpClient != null) { serverActive = ServerTcpClient.Connected; if (ServerTcpClient.Client != null) { TcpState serverState = GetTcpRemoteState(ServerTcpClient); if (serverState == TcpState.Established || serverState == TcpState.Listen || serverState == TcpState.SynReceived || serverState == TcpState.SynSent || serverState == TcpState.TimeWait) { serverSocketActive = true; } } } // Console.WriteLine(" " + Active + " " + clientActive + " " + clientSocketActive + " " + serverActive + " " + serverSocketActive); _Active = _Active && clientActive && clientSocketActive && serverActive && serverSocketActive; return(_Active); }
public TcpRow(Win32Funcs.TcpRow tcpRow) { _state = tcpRow.state; _processId = tcpRow.owningPid; int localPort = (tcpRow.localPort1 << 8) + (tcpRow.localPort2) + (tcpRow.localPort3 << 24) + (tcpRow.localPort4 << 16); long localAddress = tcpRow.localAddr; _localEndPoint = new IPEndPoint(localAddress, localPort); int remotePort = (tcpRow.remotePort1 << 8) + (tcpRow.remotePort2) + (tcpRow.remotePort3 << 24) + (tcpRow.remotePort4 << 16); long remoteAddress = tcpRow.remoteAddr; _remoteEndPoint = new IPEndPoint(remoteAddress, remotePort); }
/// <summary> /// This method is called when the asynchronous acceptance of incoming connection is complete. /// </summary> /// <param name="ar"></param> private void AcceptCallback(IAsyncResult ar) { try { TcpState tcpState = (TcpState)ar.AsyncState; string key = tcpState.Key; TcpListener tcpListener = (TcpListener)tcpState.TcpObject; TcpClient tcpClient = tcpListener.EndAcceptTcpClient(ar); SetTcpClient(tcpClient, key, FileTransfer.Modes.Send); } catch (Exception ex) { ErrorHandler.ShowError(ex); } }
/// <summary> /// This method is called when asynchronous connection to a remote server is complete. /// </summary> /// <param name="ar"></param> private void ConnectCallback(IAsyncResult ar) { try { TcpState tcpState = (TcpState)ar.AsyncState; string key = tcpState.Key; TcpClient tcpClient = (TcpClient)tcpState.TcpObject; tcpClient.EndConnect(ar); SetTcpClient(tcpClient, key, FileTransfer.Modes.Receive); } catch (Exception ex) { ErrorHandler.ShowError(ex); } }
public TcpRow(IpHelper.TcpRow tcpRow) { state = tcpRow.state; ProcessId = tcpRow.owningPid; var localPort = (tcpRow.localPort1 << 8) + (tcpRow.localPort2) + (tcpRow.localPort3 << 24) + (tcpRow.localPort4 << 16); long localAddress = tcpRow.localAddr; LocalEndPoint = new IPEndPoint(localAddress, localPort); var remotePort = (tcpRow.remotePort1 << 8) + (tcpRow.remotePort2) + (tcpRow.remotePort3 << 24) + (tcpRow.remotePort4 << 16); long remoteAddress = tcpRow.remoteAddr; RemoteEndPoint = new IPEndPoint(remoteAddress, remotePort); }
/// <summary> /// 关闭相连的scoket以及关联的TcpState,释放所有的资源 /// </summary> /// <param name="stateOne">TcpState</param> /// <param name="str">原因</param> private void socketRemove(TcpState stateOne, string str) { if (stateOne == null) { return; } stateOne.WorkSocket.Close(); if (state.Remove(stateOne)) //当没有登录的时候断掉,不触发下面的事件 { CommonMethod.eventInvoket(() => { Disconnection(stateOne.IpEndPoint, str); }); //当客户端断掉的时候触发此事件 FileOperate(stateOne.IpEndPoint.ToString() + "已经断开"); //记录 FileStart.FileStopITxBase(stateOne); } stateOne = null; }
/// <summary>使用指定的本端與遠端位址、通訊埠編號與連線狀態來初始化 CJF.Net.SocketInfo 類別的新執行個體。</summary> /// <param name="localEndPoint">本地端位址和通訊埠編號的 System.Net.IPEndPoint 類別</param> /// <param name="remoteEndPoint">本地端位址和通訊埠編號的 System.Net.IPEndPoint 類別</param> /// <param name="state">連線狀態</param> /// <param name="ownerProcessId">擁有的應用程式行程代碼</param> public SocketInfo(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, TcpState state, int ownerProcessId) { if (localEndPoint == null) { throw new ArgumentNullException("localEndPoint"); } if (remoteEndPoint == null) { throw new ArgumentNullException("remoteEndPoint"); } _LocalEndPoint = localEndPoint; _RemoteEndPoint = remoteEndPoint; _State = state; _Process = Process.GetProcessById(ownerProcessId); }
public Connection(ref NetworkInformation.UdpRowOwnerPid info) { int port = NetworkOrderToHost(info.LocalPort); var ip = new IPAddress(info.LocalAddr); _localEndPoint = new IPEndPoint(ip, port); port = 0; ip = IPAddress.Any; _remoteEndPoint = new IPEndPoint(ip, port); _owningProcessId = info.OwningPid; _connectType = ConnectType.Udp; _state = 0; }
private static async Task Send(TcpClient tc, NetworkStream stream) { Thread.Sleep(500); TcpState tcpState = tc.GetClientState(); if (!tc.Connected) { return; } if (tcpState == TcpState.Established) { DataPayload dp = new DataPayload(); byte[] byteMsg = Encoding.Default.GetBytes(SendMessage + Environment.NewLine); await stream.WriteAsync(byteMsg, 0, byteMsg.Length).ConfigureAwait(false); } }
/// <summary> /// TCP协议使用的数据第二层分配中心;把数据归类; /// </summary> /// <param name="stateOne"></param> /// <param name="statecode"></param> internal void TcpCodeManage(TcpState stateOne, StateCode statecode) { if (statecode == null || stateOne == null) { return; } if (statecode.State == PasswordCode._verificationCode) //说明是暗号;抛给暗号处理中心 { byte haveDate = EncryptionDecryptVerification.DecryptVerification(statecode.DateByte); VerificationCodeManage(stateOne, haveDate); } else { codeManage(stateOne, statecode); } }
public void Disconnect() { if (State != TcpState.Closed) { try { TcpSocket.Close(); } catch (Exception ex) { Log("Disconnect", ex.Message); } } State = TcpState.Closed; }
public void Close(int reason = 0) { _logger?.TraceFormat("Closed From {0}", _remoteEndPoint); if (_state == TcpState.Connected || _state == TcpState.Closing) { _client.Close(); _state = TcpState.Closed; if (Closed != null) { Closed(this, reason); } } }
public override TcpConnectionInformation[] GetActiveTcpConnections() { List <string[]> list = new List <string[]>(); this.GetRows(this.TcpFile, list); this.GetRows(this.Tcp6File, list); TcpConnectionInformation[] array = new TcpConnectionInformation[list.Count]; for (int i = 0; i < array.Length; i++) { IPEndPoint local = this.ToEndpoint(list[i][1]); IPEndPoint remote = this.ToEndpoint(list[i][2]); TcpState state = (TcpState)int.Parse(list[i][3], NumberStyles.HexNumber); array[i] = new TcpConnectionInformationImpl(local, remote, state); } return(array); }
protected virtual void Dispose(bool _disposing) { if (mDisposed) { return; } mDisposed = true; if (IsCOrD()) { return; } MessageDelgate = null; mMsgHandlerList.Clear(); _DisConnect(); mState = TcpState.Disposed; }
private void ConnectCheckLoop() { while (!shutdown) { //IPEndPoint[] endPoints = IPGlobalProperties.GetActiveTcpListeners(); try { foreach (KeyValuePair <HandleClient, HandleClient> el in ClientList) { try { TcpState ConnectState = GetState(el.Key.ClientSocket); if (!ConnectState.Equals(TcpState.Established)) { RemoveClient(el.Key); } else { continue; } } catch (SocketException se) { //share.EventLog(string.Format("{0} (0) > {1}", MethodBase.GetCurrentMethod().Name, se.Message), false); share.EventLog(null, string.Empty, string.Format("\t{0} (0) > {1}", MethodBase.GetCurrentMethod().Name, se.Message), false); RemoveClient(el.Key); } catch (Exception ex) { //share.EventLog(string.Format("{0} (1) > {1}", MethodBase.GetCurrentMethod().Name, ex.Message), false); share.EventLog(null, string.Empty, string.Format("\t{0} (1) > {1}", MethodBase.GetCurrentMethod().Name, ex.Message), false); RemoveClient(el.Key); } System.Threading.Thread.Sleep(100); } } catch (Exception ex) { //share.EventLog(string.Format("{0} (2) > {1}", MethodBase.GetCurrentMethod().Name, ex.Message), false); share.EventLog(null, string.Empty, string.Format("\t{0} (2) > {1}", MethodBase.GetCurrentMethod().Name, ex.Message), false); } } }
/// <summary> /// 判断网络状态是否连接 /// </summary> /// <returns></returns> public bool IsConnected() { bool bRet = false; try { if (this.mNetSocket == null) { return(bRet); } if (!this.mNetSocket.Connected) { return(bRet); } IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections(); foreach (TcpConnectionInformation c in tcpConnections) { TcpState stateOfConnection = c.State; if (!c.LocalEndPoint.Equals(this.mNetSocket.LocalEndPoint)) { continue; } if (!c.RemoteEndPoint.Equals(this.mNetSocket.RemoteEndPoint)) { continue; } if (stateOfConnection == TcpState.Established) { bRet = true; break; } } } catch (Exception ex) { YunLib.LogWriter.Log(ex.ToString()); } return(bRet); }
private void ListenTimer_Elapsed(object sender, ElapsedEventArgs e) { listenTimer.Stop(); try { if (PoolCache.CurrentTask != null && PoolCache.CurrentTask.State == MiningState.Mining) { return; } if (PoolCache.CurrentTask == null && PoolCache.poolTasks.Any()) { PoolCache.CurrentTask = PoolCache.poolTasks.FirstOrDefault(); } PoolCache.poolTasks.Remove(PoolCache.CurrentTask); if (PoolCache.CurrentTask != null && PoolCache.CurrentTask.State == MiningState.Wait) { foreach (Miner miner in PoolCache.WorkingMiners) { try { var tcpstate = new TcpState() { Client = miner.Client, Stream = miner.Stream, Address = miner.ClientAddress }; StartCommand.Send(tcpstate, PoolCache.CurrentTask.CurrentStartMsg); } catch (Exception ex) { LogHelper.Error(ex.ToString()); PoolCache.WorkingMiners.Remove(miner); } } PoolCache.CurrentTask.State = MiningState.Mining; } } catch (Exception ex) { LogHelper.Error(ex.ToString()); } finally { listenTimer.Start(); } }
public Connection(ref NetworkInformation.Tcp6RowOwnerPid info) { int port = NetworkOrderToHost(info.LocalPort); long scope = NetworkOrderToHost(info.LocalScopeId); var ip = new IPAddress(info.LocalAddr, scope); _localEndPoint = new IPEndPoint(ip, port); port = NetworkOrderToHost(info.RemotePort); scope = NetworkOrderToHost(info.RemoteScopeId); ip = new IPAddress(info.RemoteAddr, scope); _remoteEndPoint = new IPEndPoint(ip, port); _owningProcessId = info.OwningPid; _connectType = ConnectType.TcPv6; _state = info.State; }
public SystemTcpConnectionInformation (IPEndPoint local, IPEndPoint remote, TcpState state) { localEndPoint = local; remoteEndPoint = remote; this.state = state; }
public TcpConnectionInformationImpl (IPEndPoint local, IPEndPoint remote, TcpState state) { this.local = local; this.remote = remote; this.state = state; }
public void CleanClose(string reason, bool reconnect) { if (State == TcpState.Connecting) ByeMessage = reason; if (State == TcpState.Connected) { ByeMessage = reason; var bye = new GenericPacket("Bye"); bye.Data = new Dictionary<string, string> { {"Reason", reason} }; SendPacket(bye); Log("CleanClose", "Closing connection: " + reason); TcpSocket.Close(); } State = TcpState.Closed; }
public void Disconnect() { if (State != TcpState.Closed) { try { if (Core.Sim == null) TcpSocket.Close(); else Core.Sim.Internet.SendPacket(SimPacketType.TcpClose, Network, null, new IPEndPoint(RemoteIP, TcpPort), this); } catch (Exception ex) { LogException("Disconnect", ex.Message); } } State = TcpState.Closed; }
public TcpConnection(IPacketSerializer serializer, ILog logger) { _state = TcpState.Closed; _logger = logger; _packetSerializer = serializer; }
private void ConnectCallback(IAsyncResult ar) { try { _client.EndConnect(ar); _localEndPoint = _client.Client.LocalEndPoint; _remoteEndPoint = _client.Client.RemoteEndPoint; _logger?.TraceFormat("Connected {0} with {1}", _remoteEndPoint, _localEndPoint); } catch (SocketException e) { _state = TcpState.Closed; _logger?.TraceFormat("Connect Failed {0} with {1}", e, _remoteEndPoint, e.SocketErrorCode); Closed?.Invoke(this, (int)e.SocketErrorCode); return; } catch (Exception e) { _state = TcpState.Closed; _logger?.TraceFormat("Connect Failed {0}", e, _remoteEndPoint); Closed?.Invoke(this, 0); return; } StartCommunication(); }
public void CleanClose(string reason, bool reconnect) { if (State == TcpState.Connecting) ByeMessage = reason; if (State == TcpState.Connected) { ByeMessage = reason; Bye bye = new Bye(); bye.SenderID = Network.Local.UserID; bye.ContactList = Network.Routing.Find(UserID, 8); bye.Message = reason; bye.Reconnect = reconnect; SendPacket(bye); Network.UpdateLog("Tcp", "Closing connection to " + ToString() + " " + reason); } State = TcpState.Closed; }
public void CloseSend() { if (_state == TcpState.Connected) { _state = TcpState.Closing; if (_sendPacketQueue.Count > 0) { lock (_sendPacketQueue) _sendPacketQueue.Add(null); } else { lock (_sendPacketQueue) _sendPacketQueue.Add(null); ProcessSend(); } } }
public void SetConnected() { SendBuffer = new byte[BUFF_SIZE]; RecvBuffer = new byte[BUFF_SIZE]; FinalRecvBuffer = new byte[BUFF_SIZE]; FinalSendBuffer = new byte[BUFF_SIZE]; State = TcpState.Connected; if (Core.Sim != null) return; try { TcpSocket.BeginReceive( RecvBuffer, RecvBuffSize, RecvBuffer.Length, SocketFlags.None, new AsyncCallback(Socket_Receive), TcpSocket); } catch(Exception ex) { LogException("SetConnected", ex.Message); Disconnect(); } }
private static void ValidateInfo(TcpConnectionInformation tcpConnectionInformation, IPEndPoint localEP, IPEndPoint remoteEP, TcpState state) { Assert.Equal(localEP, tcpConnectionInformation.LocalEndPoint); Assert.Equal(remoteEP, tcpConnectionInformation.RemoteEndPoint); Assert.Equal(state, tcpConnectionInformation.State); }
bool IsListenerState (TcpState state) { switch (state) { case TcpState.SynSent: case TcpState.Listen: case TcpState.FinWait1: case TcpState.FinWait2: case TcpState.CloseWait: return true; } return false; }
public void Close(int reason = 0) { _logger?.TraceFormat("Closed From {0}", _remoteEndPoint); if (_state == TcpState.Connected || _state == TcpState.Closing) { _client.Close(); _state = TcpState.Closed; if (Closed != null) Closed(this, reason); } }
public SimpleTcpConnectionInformation(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, TcpState state) { _localEndPoint = localEndPoint; _remoteEndPoint = remoteEndPoint; _state = state; }
private void StartCommunication() { _state = TcpState.Connected; ProcessRecv(); if (Connected != null) Connected(this); }