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); }
/// <summary> /// Creates a new imposter on the specified port with the TCP protocol. The Submit method /// must be called on the client in order to submit the imposter to mountebank. /// </summary> /// <param name="port">The port the imposter will be set up to receive requests on</param> /// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param> /// <param name="mode">The mode of the imposter, text or binary. This defines the encoding for request/response data</param> /// <returns>The newly created imposter</returns> public TcpImposter CreateTcpImposter(int port, string name = null, TcpMode mode = TcpMode.Text) { var imposter = new TcpImposter(port, name, mode); Imposters.Add(imposter); return(imposter); }
public TcpImposter(int?port, string name, TcpMode mode, bool recordRequests = false, TcpResponseFields defaultResponse = null) : base(port, Enums.Protocol.Tcp, name, recordRequests) { Stubs = new List <TcpStub>(); Mode = mode.ToString().ToLower(); DefaultResponse = defaultResponse; }
public int Setup(int contextId, TcpMode mode, string remoteAddress, int remotePort, int sourcePort, bool dataMode, bool enableUrc) { Host = remoteAddress; Port = remotePort; Urc = enableUrc; DataMode = dataMode; return(Id); }
/// <summary> /// 停止在本机的监听 /// </summary> public void StopListen(bool closeConnect) { if (closeConnect) { CloseConnect(); } if (_listenning) { _tl.Stop(); onStopListen(); } _tcpMode = TcpMode.Unknown; }
/// <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 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: 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> /// ֹͣ�ڱ����ļ��� /// </summary> public void StopListen(bool closeConnect) { if (closeConnect) CloseConnect(); if (_listenning) { _tl.Stop(); onStopListen(); } _tcpMode = TcpMode.Unknown; }
/// <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; }
public TcpImposter(int?port, string name, TcpMode mode, bool recordRequests = false) : base(port, Enums.Protocol.Tcp, name, recordRequests) { Stubs = new List <TcpStub>(); Mode = mode.ToString().ToLower(); }
/// <summary> /// Creates a new imposter on the specified port with the TCP protocol. The Submit method /// must be called on the client in order to submit the imposter to mountebank. /// </summary> /// <param name="port">The port the imposter will be set up to receive requests on</param> /// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param> /// <param name="mode">The mode of the imposter, text or binary. This defines the encoding for request/response data</param> /// <param name="recordRequests"> /// Enables recording requests to use the imposter as a mock. See /// <see href="http://www.mbtest.org/docs/api/mocks">here</see> for more details on Mountebank /// verification. /// </param> /// <returns>The newly created imposter</returns> public TcpImposter CreateTcpImposter(int?port = null, string name = null, TcpMode mode = TcpMode.Text, bool recordRequests = false) { return(new TcpImposter(port, name, mode, recordRequests)); }
/// <summary> /// Creates a new imposter on the specified port with the TCP protocol. The Submit method /// must be called on the client in order to submit the imposter to mountebank. /// </summary> /// <param name="port">The port the imposter will be set up to receive requests on</param> /// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param> /// <param name="mode">The mode of the imposter, text or binary. This defines the encoding for request/response data</param> /// <returns>The newly created imposter</returns> public TcpImposter CreateTcpImposter(int port, string name = null, TcpMode mode = TcpMode.Text) { return new TcpImposter(port, name, mode); }
public TcpImposter(int port, string name, TcpMode mode) : base(port, MbDotNet.Enums.Protocol.Tcp, name) { Stubs = new List<TcpStub>(); Mode = mode.ToString().ToLower(); }
public TcpImposter(int?port, string name, TcpMode mode) : base(port, Enums.Protocol.Tcp, name) { Stubs = new List <TcpStub>(); Mode = mode.ToString().ToLower(); }
/// <summary> /// Creates a new imposter on the specified port with the TCP protocol. The Submit method /// must be called on the client in order to submit the imposter to mountebank. /// </summary> /// <param name="port">The port the imposter will be set up to receive requests on</param> /// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param> /// <param name="mode">The mode of the imposter, text or binary. This defines the encoding for request/response data</param> /// <returns>The newly created imposter</returns> public TcpImposter CreateTcpImposter(int port, string name = null, TcpMode mode = TcpMode.Text) { return(new TcpImposter(port, name, mode)); }
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); }
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> /// Creates a new imposter on the specified port with the TCP protocol. The Submit method /// must be called on the client in order to submit the imposter to mountebank. /// </summary> /// <param name="port">The port the imposter will be set up to receive requests on</param> /// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param> /// <param name="mode">The mode of the imposter, text or binary. This defines the encoding for request/response data</param> /// <param name="recordRequests"> /// Enables recording requests to use the imposter as a mock. See /// <see href="http://www.mbtest.org/docs/api/mocks">here</see> for more details on Mountebank /// verification. /// </param> /// <param name="defaultResponse">The default response to send if no predicate matches</param> /// <returns>The newly created imposter</returns> public TcpImposter CreateTcpImposter(int?port = null, string name = null, TcpMode mode = TcpMode.Text, bool recordRequests = false, TcpResponseFields defaultResponse = null) { return(new TcpImposter(port, name, mode, recordRequests, defaultResponse)); }