/// <summary> /// 异步连接到一个支持SM协议的计算机端口 /// </summary> /// <param name="tstr">远程TcpStruct</param> public void AsyncConnectTo(TcpStruct tstr) { _remoteTcpStruct.IP = tstr.IP; _remoteTcpStruct.Port = tstr.Port; Threads.ExecAsync(async_th_connect); }
internal void onError(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, TcpError error, Exception ex, TcpOptionType type, ITcpReader tcpReader) { if (OnError != null) { OnError(localTcpInfo, remoteTcpInfo, error, ex, type, tcpReader); } }
internal void onReceivedData(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, SmmpPacket packet, __listen__readSmmp tcpReader) { if (OnReceivedData != null) { OnReceivedData(localTcpInfo, remoteTcpInfo, packet, tcpReader); } }
internal void onConnectionEvent(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, ITcpReader tcpClient, int clientID) { if (OnConnectionEvent != null) { OnConnectionEvent(localTcpInfo, remoteTcpInfo, tcpClient, clientID); } }
internal void onConnectionEvent(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, __listen__readSmmp tcpClient, int clientID) { if (OnConnectionEvent != null) { OnConnectionEvent(localTcpInfo, remoteTcpInfo, tcpClient, clientID); } }
internal void onReceivedData(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, byte[] data, ITcpReader tcpReader) { if (OnReceivedData != null) { OnReceivedData(localTcpInfo, remoteTcpInfo, data, tcpReader); } }
internal void onClose(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, int clientID) { _remoteTcpStruct.IP = null; _remoteTcpStruct.Port = 0; if (_tcpMode == TcpMode.Client) { CloseConnect(); _tcpMode = TcpMode.Unknown; } else if (_tcpMode == TcpMode.Server) { lock (_tcp_Reader_Array) { foreach (object obj in _tcp_Reader_Array) { if (obj == null) { continue; } if (((__listen__readSmtcp)obj).ClientID == clientID) { _tcp_Reader_Array.Remove(obj); break; } } } } onTcpEvents(_localTcpStruct, _remoteTcpStruct, TcpOptionType.Disconnected, null); }
internal void onTcpEvents(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, TcpOptionType type, ITcpReader tcpReader) { switch (type) { case TcpOptionType.StartListen: _listenning = true; break; case TcpOptionType.StopListen: _listenning = false; _listenWork = false; break; case TcpOptionType.ClientConnected: break; case TcpOptionType.Connected: break; case TcpOptionType.Disconnected: break; case TcpOptionType.Connecting: Thread.Sleep(0); break; default: break; } if (OnTcpEvents != null) { OnTcpEvents(localTcpInfo, remoteTcpInfo, type, tcpReader); } }
private void onReceivedData(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, SmmpPacket packet, byte[] rawData) { if (OnReceivedData != null) { OnReceivedData(localTcpInfo, remoteTcpInfo, packet, this); } _tcp.onReceivedData(_tcp._localTcpStruct, _remoteTcpStruct, packet, this); }
private void onReceivedData(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, byte[] data) { if (OnReceivedData != null) { OnReceivedData(localTcpInfo, remoteTcpInfo, data, this); } _tcp.onReceivedData(_tcp._localTcpStruct, _remoteTcpStruct, data, this); }
/// <summary> /// 在指定的端口开始监听网络 /// </summary> /// <param name="tstr">指定远程的计算机Tcp结构</param> public void StartListen(TcpStruct tstr) { try { if (_tl == null) { _tl = new TcpListener(tstr.IP, tstr.Port); } _tl.Start(); } catch (Exception ex) { onError(tstr, _remoteTcpStruct, TcpError.UncreateListen, ex, TcpOptionType.CreateListen, null); return; } _localTcpStruct.IP = tstr.IP; _localTcpStruct.Port = tstr.Port; onTcpEvents(_localTcpStruct, _remoteTcpStruct, TcpOptionType.StartListen, null); _tcpMode = TcpMode.Server; ReadDataFromListen(); }
/// <summary> /// 连接到一个支持SM协议的计算机端口 /// </summary> /// <param name="tstr">指定远程的计算机Tcp结构</param> public TcpResult ConnectTo(TcpStruct tstr) { TcpResult result = new TcpResult(); result.Success = false; onTcpEvents(this._localTcpStruct, this._remoteTcpStruct, TcpOptionType.Connecting, null); if (Connected) { onError(_localTcpStruct, _remoteTcpStruct, TcpError.TcpClientIsConnected, null, TcpOptionType.Connecting, null); result.Success = false; result.Error = TcpError.TcpClientIsConnected; return(result); } _tc = new TcpClient(); try { _tc.Connect(tstr.IP, tstr.Port); _tcpMode = TcpMode.Client; _ns = _tc.GetStream(); result.Success = true; } catch (Exception ex) { onError(_localTcpStruct, _remoteTcpStruct, TcpError.ServerOffline, ex, TcpOptionType.Connecting, null); result.Error = TcpError.ServerOffline; result.Success = false; return(result); } _remoteTcpStruct.IP = tstr.IP; _remoteTcpStruct.Port = tstr.Port; FormatIPStringToTcpStruct(_tc.Client.LocalEndPoint.ToString(), ref _localTcpStruct); onTcpEvents(_localTcpStruct, _remoteTcpStruct, TcpOptionType.Connected, null); if (!UseBlockRead) { Threads.ExecAsync(ReadDataFromConnectRemote); } return(result); }
internal void onError(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, TcpError error, Exception ex, TcpOptionType type, __listen__readSmmp tcpReader) { if (OnError != null) OnError(localTcpInfo, remoteTcpInfo, error, ex, type, tcpReader); }
internal void onConnectionEvent(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, __listen__readSmmp tcpClient, int clientID) { if (OnConnectionEvent != null) OnConnectionEvent(localTcpInfo, remoteTcpInfo, tcpClient, clientID); }
internal void onClose(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, int clientID) { _remoteTcpStruct.IP = null; _remoteTcpStruct.Port = 0; if (_tcpMode == TcpMode.Client) { CloseConnect(); _tcpMode = TcpMode.Unknown; } else if (_tcpMode == TcpMode.Server) { lock (_tcp_Reader_Array) { foreach (object obj in _tcp_Reader_Array) { if (obj == null) continue; if (((__listen__readSmmp)obj).ClientID == clientID) { _tcp_Reader_Array.Remove(obj); break; } } } } onTcpEvents(_localTcpStruct, _remoteTcpStruct, TcpOptionType.Disconnected, null); }
/// <summary> /// ��ָ���Ķ˿ڿ�ʼ�������� /// </summary> /// <param name="tstr">ָ��Զ�̵ļ����Tcp�ṹ</param> public void StartListen(TcpStruct tstr) { try { if (_tl == null) _tl = new TcpListener(tstr.IP, tstr.Port); _tl.Start(); } catch (Exception ex) { onError(tstr, _remoteTcpStruct, TcpError.UncreateListen, ex, TcpOptionType.CreateListen, null); return; } _localTcpStruct.IP = tstr.IP; _localTcpStruct.Port = tstr.Port; onTcpEvents(_localTcpStruct, _remoteTcpStruct, TcpOptionType.StartListen, null); _tcpMode = TcpMode.Server; ReadDataFromListen(); }
/// <summary> /// ���ӵ�һ��֧��SMЭ��ļ�����˿� /// </summary> /// <param name="tstr">ָ��Զ�̵ļ����Tcp�ṹ</param> public TcpResult ConnectTo(TcpStruct tstr) { TcpResult result = new TcpResult(); result.Success = false; onTcpEvents(this._localTcpStruct, this._remoteTcpStruct, TcpOptionType.Connecting, null); if (Connected) { onError(_localTcpStruct, _remoteTcpStruct, TcpError.TcpClientIsConnected, null, TcpOptionType.Connecting, null); result.Success = false; result.Error = TcpError.TcpClientIsConnected; return result; } _tc = new TcpClient(); try { _tc.Connect(tstr.IP, tstr.Port); _tcpMode = TcpMode.Client; _ns = _tc.GetStream(); result.Success = true; } catch (Exception ex) { onError(_localTcpStruct, _remoteTcpStruct, TcpError.ServerOffline, ex, TcpOptionType.Connecting, null); result.Error = TcpError.ServerOffline; result.Success = false; return result; } _remoteTcpStruct.IP = tstr.IP; _remoteTcpStruct.Port = tstr.Port; FormatIPStringToTcpStruct(_tc.Client.LocalEndPoint.ToString(), ref _localTcpStruct); onTcpEvents(_localTcpStruct, _remoteTcpStruct, TcpOptionType.Connected, null); if (!UseBlockRead) Threads.ExecAsync(ReadDataFromConnectRemote); return result; }
/// <summary> /// �첽���ӵ�һ��֧��SMЭ��ļ�����˿� /// </summary> /// <param name="tstr">Զ��TcpStruct</param> public void AsyncConnectTo(TcpStruct tstr) { _remoteTcpStruct.IP = tstr.IP; _remoteTcpStruct.Port = tstr.Port; Threads.ExecAsync(async_th_connect); }
private void onReceivedData(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, SmmpPacket packet, byte[] rawData) { if (OnReceivedData != null) OnReceivedData(localTcpInfo, remoteTcpInfo, packet, this); _tcp.onReceivedData(_tcp._localTcpStruct, _remoteTcpStruct, packet, this); }
private void onReceivedData(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, byte[] data) { if (OnReceivedData != null) OnReceivedData(localTcpInfo, remoteTcpInfo, data, this); _tcp.onReceivedData(_tcp._localTcpStruct, _remoteTcpStruct, data, this); }
internal void onReceivedData(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, byte[] data, ITcpReader tcpReader) { if (OnReceivedData != null) OnReceivedData(localTcpInfo, remoteTcpInfo, data, tcpReader); }
internal void onConnectionEvent(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, ITcpReader tcpClient, int clientID) { if (OnConnectionEvent != null) OnConnectionEvent(localTcpInfo, remoteTcpInfo, tcpClient, clientID); }
public static string GetIPPortString(TcpStruct tcpStruct) { return tcpStruct.IP + ":" + tcpStruct.Port; }
/// <summary> /// 把一个标准EndPoint字符串填充到TcpStruct里面 /// </summary> /// <param name="ipstring">标准的EndPoint字符串</param> /// <param name="tstr">TcpStruct地址传入</param> public static void FormatIPStringToTcpStruct(string ipstring, ref TcpStruct tstr) { string[] s = ipstring.Split(new string[] { ":" }, StringSplitOptions.None); tstr.IP = IPAddress.Parse(s[0]); tstr.Port = int.Parse(s[1]); }
public static string GetIPPortString(TcpStruct tcpStruct) { return(tcpStruct.IP + ":" + tcpStruct.Port); }
internal void onReceivedData(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, SmmpPacket packet, __listen__readSmmp tcpReader) { if (OnReceivedData != null) OnReceivedData(localTcpInfo, remoteTcpInfo, packet, tcpReader); }
internal void onTcpEvents(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, TcpOptionType type, __listen__readSmmp tcpReader) { switch (type) { case TcpOptionType.StartListen: _listenning = true; break; case TcpOptionType.StopListen: _listenning = false; _listenWork = false; break; case TcpOptionType.ClientConnected: break; case TcpOptionType.Connected: break; case TcpOptionType.Disconnected: if (_tcpMode == TcpMode.Client) _tcpMode = TcpMode.Unknown; break; case TcpOptionType.Connecting: Thread.Sleep(0); break; default: break; } if (OnTcpEvents != null) OnTcpEvents(localTcpInfo, remoteTcpInfo, type, tcpReader); }
/// <summary> /// ��һ����EndPoint�ַ�����䵽TcpStruct���� /// </summary> /// <param name="ipstring">����EndPoint�ַ���</param> /// <param name="tstr">TcpStruct��ַ����</param> public static void FormatIPStringToTcpStruct(string ipstring, ref TcpStruct tstr) { string[] s = ipstring.Split(new string[] { ":" }, StringSplitOptions.None); tstr.IP = IPAddress.Parse(s[0]); tstr.Port = int.Parse(s[1]); }