private void Connect() { if (_disposing || _connecting) { return; } _connecting = true; try { while (!_stopConnectThread && !_disposing) { try { if (!_rpc.IsConnected) { _rpc.Connect(_events); } break; } catch (Exception ex) { ConnectError?.Invoke(this, ex.Message, ex.StackTrace); Thread.Sleep(10000); } } } catch (Exception ex) { _connecting = false; throw ex; } _connecting = false; }
public void Connect() { if (IsConnect) { return; } try { _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _clientSocket.Connect(this.Address, this.Port); } catch { ConnectError?.Invoke("连接异常"); return; } if (!_clientSocket.Connected) { ConnectError?.Invoke("未能连接成功"); return; } IsConnect = true; // OnConnected?.Invoke(); var thread = new Thread(ReceiveData); thread.Start(); }
/// <summary> /// 检测回送结果 /// </summary> private void StartAnalize() { if (rawInfo.Contains("我要下线")) { isConnected = true; errorCode = ConnectError.Connected; } else if (rawInfo.Contains("您当前已使用")) { errorCode = ConnectError.ReConnected; } else if (rawInfo.Contains("参数错误")) { errorCode = ConnectError.VerifyUserError; } else if (rawInfo.Contains("接入设备")) { errorCode = ConnectError.VerifyDeviceError; } else { errorCode = ConnectError.OtherError; otherInfo = rawInfo.Split(new string[] { "('", "')" }, StringSplitOptions.RemoveEmptyEntries)[1]; } }
private void ConnectDB(string sqlQuery) { try { _dbaseConnection = new SQLiteConnection(_connectionString); _dbaseConnection.Open(); _dataAdapter = new SQLiteDataAdapter(sqlQuery, _dbaseConnection); } catch (Exception) { ConnectError?.Invoke(this, EventArgs.Empty); } }
//初始化按钮 private void btnInitial_Click(object sender, EventArgs e) { ServerA = new ServerSocket(); ServerB = new ServerSocket(); URControllerA = new URControlHandle(); URControllerB = new URControlHandle(); //按钮的可用和不可用确保只会初始化一次 this.btnInitial.Enabled = false; this.btnReset.Enabled = true; ServerIP = txtIPAddressPC.Text; ServerA.server_listenPort = Convert.ToInt32(txtPortPCToRobotA.Text); ServerB.server_listenPort = Convert.ToInt32(txtPortPCToRobotB.Text); ClientAIP = txtIPAddressRobotA.Text; ClientAPort = Convert.ToInt32(txtPortRobotA.Text); ClientBIP = txtIPAddressRobotB.Text; ClientBPort = Convert.ToInt32(txtPortRobotB.Text); //AB两台机器分开 try { ServerA.Create_Server(); ServerA.OnConnectionSuccess += new ServerSocket.ConnectionSuccess(ConnectOverA); ServerA.OnReceiveSuccess += new ServerSocket.ReceiveSuccess(ReceiveOverA); ServerA.OnClientDisconnect += new ServerSocket.ClientDisconnect(DisconnectOverA); URControllerA.Creat_client(ClientAIP, ClientAPort); } catch (Exception ConnectError) { MessageBox.Show("无法连接A机器" + ConnectError.ToString()); } try { ServerB.Create_Server(); ServerB.OnConnectionSuccess += new ServerSocket.ConnectionSuccess(ConnectOverB); ServerB.OnReceiveSuccess += new ServerSocket.ReceiveSuccess(ReceiveOverB); ServerB.OnClientDisconnect += new ServerSocket.ClientDisconnect(DisconnectOverB); URControllerB.Creat_client(ClientBIP, ClientBPort); } catch (Exception ConnectError) { MessageBox.Show("无法连接B机器" + ConnectError.ToString()); } }
public static IConnectionConfiguration CopyWith( this IConnectionConfiguration configuration, IRetry connectionRetry = null, IVersionSupport versionSupport = null, TimeSpan?requestTimeout = null, int?readBufferSize = null, int?writeBufferSize = null, bool?isTcpKeepalive = null, IEnumerable <IMembershipEncoder> encoders = null, ISslConfiguration sslConfiguration = null, ConnectError onDisconnected = null, Connecting onConnecting = null, Connecting onConnected = null, Writing onWriting = null, StartingBytes onWritingBytes = null, FinishedBytes onWroteBytes = null, WriteSuccess onWritten = null, WriteError onWriteFailed = null, Reading onReading = null, StartingBytes onReadingBytes = null, FinishedBytes onReadBytes = null, ReadSuccess onRead = null, ReadError onReadFailed = null, ProduceRequestMessages onProduceRequestMessages = null) { return(new ConnectionConfiguration( connectionRetry ?? configuration.ConnectionRetry, versionSupport ?? configuration.VersionSupport, requestTimeout ?? configuration.RequestTimeout, readBufferSize ?? configuration.ReadBufferSize, writeBufferSize ?? configuration.WriteBufferSize, isTcpKeepalive ?? configuration.IsTcpKeepalive, encoders ?? configuration.Encoders.Values, sslConfiguration ?? configuration.SslConfiguration, onDisconnected ?? configuration.OnDisconnected, onConnecting ?? configuration.OnConnecting, onConnected ?? configuration.OnConnected, onWriting ?? configuration.OnWriting, onWritingBytes ?? configuration.OnWritingBytes, onWroteBytes ?? configuration.OnWroteBytes, onWritten ?? configuration.OnWritten, onWriteFailed ?? configuration.OnWriteFailed, onReading ?? configuration.OnReading, onReadingBytes ?? configuration.OnReadingBytes, onReadBytes ?? configuration.OnReadBytes, onRead ?? configuration.OnRead, onReadFailed ?? configuration.OnReadFailed, onProduceRequestMessages ?? configuration.OnProduceRequestMessages)); }
/// <summary> /// Configuration for the tcp connection. /// </summary> /// <param name="connectionRetry">Retry details for (re)establishing the connection.</param> /// <param name="versionSupport">Support for different protocol versions for Kakfa requests and responses.</param> /// <param name="requestTimeout">The maximum time to wait for requests.</param> /// <param name="readBufferSize">The buffer size to use for the socket, when receiving bytes.</param> /// <param name="writeBufferSize">The buffer size to use for the socket, when sending bytes.</param> /// <param name="isTcpKeepalive">TCP keepalive option.</param> /// <param name="encoders">Custom Encoding support for different protocol types</param> /// <param name="sslConfiguration">Configuration for SSL encrypted communication</param> /// <param name="onDisconnected">Triggered when the tcp socket is disconnected.</param> /// <param name="onConnecting">Triggered when the tcp socket is connecting.</param> /// <param name="onConnected">Triggered after the tcp socket is successfully connected.</param> /// <param name="onWriting">Triggered when writing to the tcp stream.</param> /// <param name="onWritingBytes">Triggered when writing a chunk of bytes to the tcp stream.</param> /// <param name="onWroteBytes">Triggered after successfully writing a chunk of bytes to the tcp stream.</param> /// <param name="onWritten">Triggered after having successfully written to the tcp stream.</param> /// <param name="onWriteFailed">Triggered after failing to write to the tcp stream.</param> /// <param name="onReading">Triggered when starting to read a message's bytes from the tcp stream.</param> /// <param name="onReadingBytes">Triggered when reading a chunk of bytes from the tcp stream.</param> /// <param name="onReadBytes">Triggered after successfully reading a chunk of bytes from the tcp stream.</param> /// <param name="onRead">Triggered after having successfully read a message's bytes from the tcp stream.</param> /// <param name="onReadFailed">Triggered after failing to read from the tcp stream.</param> /// <param name="onProduceRequestMessages">Triggered when encoding ProduceRequest messages.</param> public ConnectionConfiguration( IRetry connectionRetry = null, IVersionSupport versionSupport = null, TimeSpan?requestTimeout = null, int?readBufferSize = null, int?writeBufferSize = null, bool?isTcpKeepalive = null, IEnumerable <IMembershipEncoder> encoders = null, ISslConfiguration sslConfiguration = null, ConnectError onDisconnected = null, Connecting onConnecting = null, Connecting onConnected = null, Writing onWriting = null, StartingBytes onWritingBytes = null, FinishedBytes onWroteBytes = null, WriteSuccess onWritten = null, WriteError onWriteFailed = null, Reading onReading = null, StartingBytes onReadingBytes = null, FinishedBytes onReadBytes = null, ReadSuccess onRead = null, ReadError onReadFailed = null, ProduceRequestMessages onProduceRequestMessages = null ) { ConnectionRetry = connectionRetry ?? Defaults.ConnectionRetry(); VersionSupport = versionSupport ?? Connections.VersionSupport.Kafka10; RequestTimeout = requestTimeout ?? TimeSpan.FromSeconds(Defaults.RequestTimeoutSeconds); ReadBufferSize = readBufferSize.GetValueOrDefault(Defaults.BufferSize); WriteBufferSize = writeBufferSize.GetValueOrDefault(Defaults.BufferSize); IsTcpKeepalive = isTcpKeepalive ?? Defaults.IsTcpKeepalive; Encoders = Defaults.Encoders(encoders); SslConfiguration = sslConfiguration; OnDisconnected = onDisconnected; OnConnecting = onConnecting; OnConnected = onConnected; OnWriting = onWriting; OnWritingBytes = onWritingBytes; OnWroteBytes = onWroteBytes; OnWritten = onWritten; OnWriteFailed = onWriteFailed; OnReading = onReading; OnReadingBytes = onReadingBytes; OnReadBytes = onReadBytes; OnRead = onRead; OnReadFailed = onReadFailed; OnProduceRequestMessages = onProduceRequestMessages; }
protected override void OnConnectFailed(ConnectError reason, int?socketErrorCode) { if (ConnectFailed == null) { return; } if (socketErrorCode == null) { ConnectFailed(this, new ConnectFailedEventArgs(reason)); } else { ConnectFailed(this, new ConnectFailedEventArgs(reason, (int)socketErrorCode)); } }
/// <summary> /// Configuration for the tcp connection. /// </summary> /// <param name="connectionRetry">Retry details for (re)establishing the connection.</param> /// <param name="versionSupport">Support for different protocol versions for Kakfa requests and responses.</param> /// <param name="requestTimeout">The maximum time to wait for requests.</param> /// <param name="encoders">Custom Encoding support for different protocol types</param> /// <param name="sslConfiguration">Configuration for SSL encrypted communication</param> /// <param name="onDisconnected">Triggered when the tcp socket is disconnected.</param> /// <param name="onConnecting">Triggered when the tcp socket is connecting.</param> /// <param name="onConnected">Triggered after the tcp socket is successfully connected.</param> /// <param name="onWriteEnqueued">Triggered after enqueing async write task for writing to the tcp stream.</param> /// <param name="onWriting">Triggered when writing to the tcp stream.</param> /// <param name="onWritten">Triggered after having successfully written to the tcp stream.</param> /// <param name="onWriteFailed">Triggered after failing to write to the tcp stream.</param> /// <param name="onReading">Triggered when starting to read a message's bytes from the tcp stream.</param> /// <param name="onReadingChunk">Triggered when reading a chunk of bytes from the tcp stream.</param> /// <param name="onReadChunk">Triggered after successfully reading a chunk of bytes from the tcp stream.</param> /// <param name="onRead">Triggered after having successfully read a message's bytes from the tcp stream.</param> /// <param name="onReadFailed">Triggered after failing to read from the tcp stream.</param> /// <param name="onProduceRequestMessages">Triggered when encoding ProduceRequest messages.</param> public ConnectionConfiguration( IRetry connectionRetry = null, IVersionSupport versionSupport = null, TimeSpan?requestTimeout = null, IEnumerable <IProtocolTypeEncoder> encoders = null, ISslConfiguration sslConfiguration = null, ConnectError onDisconnected = null, Connecting onConnecting = null, Connecting onConnected = null, Writing onWriteEnqueued = null, Writing onWriting = null, WriteSuccess onWritten = null, WriteError onWriteFailed = null, Reading onReading = null, ReadingChunk onReadingChunk = null, ReadChunk onReadChunk = null, Read onRead = null, ReadError onReadFailed = null, ProduceRequestMessages onProduceRequestMessages = null ) { ConnectionRetry = connectionRetry ?? Defaults.ConnectionRetry(); VersionSupport = versionSupport ?? Connections.VersionSupport.Kafka8; RequestTimeout = requestTimeout ?? TimeSpan.FromSeconds(Defaults.RequestTimeoutSeconds); Encoders = encoders != null ? encoders.ToImmutableDictionary(e => e.Type) : ImmutableDictionary <string, IProtocolTypeEncoder> .Empty; SslConfiguration = sslConfiguration; OnDisconnected = onDisconnected; OnConnecting = onConnecting; OnConnected = onConnected; OnWriteEnqueued = onWriteEnqueued; OnWriting = onWriting; OnWritten = onWritten; OnWriteFailed = onWriteFailed; OnReading = onReading; OnReadingChunk = onReadingChunk; OnReadChunk = onReadChunk; OnRead = onRead; OnReadFailed = onReadFailed; OnProduceRequestMessages = onProduceRequestMessages; }
/// <summary> /// TODO /// </summary> /// <param name="reason"></param> /// <param name="socketErrorCode"></param> public ConnectFailedEventArgs(ConnectError reason, int socketErrorCode) { Reason = reason; SocketErrorCode = socketErrorCode; }
/// <summary> /// TODO /// </summary> /// <param name="reason"></param> /// <param name="socketErrorCode"></param> public ConnectFailedEventArgs(ConnectError reason, int socketErrorCode) { Reason = reason; SocketErrorCode = socketErrorCode; }
protected abstract void OnConnectFailed(ConnectError error, int? socketErrorCode);
private static extern IntPtr Theta_Connect(string ip_address, string game_object_name, ConnectSuccess success, ConnectError error);
protected abstract void OnConnectFailed(ConnectError error, int?socketErrorCode);
protected override void OnConnectFailed(ConnectError reason, int? socketErrorCode) { if (ConnectFailed == null) return; if (socketErrorCode == null) ConnectFailed(this, new ConnectFailedEventArgs(reason)); else ConnectFailed(this, new ConnectFailedEventArgs(reason, (int)socketErrorCode)); }
/// <summary> /// Instantiate a new <see cref="ConnectResult"/> where the result is an error. /// <see cref="SessionState"/> will be <see cref="SessionState.Unknown"/>. /// <see cref="ConnectReturnCode"/> will be <see cref="ConnectReturnCode.Unknown"/>. /// </summary> /// <param name="connectError">The reason the client could not connect.</param> public ConnectResult(ConnectError connectError) { ConnectError = connectError; SessionState = SessionState.Unknown; ConnectReturnCode = ConnectReturnCode.Unknown; }
public ConnectFailedEventArgs(ConnectError reason) { Reason = reason; }
/// <summary> /// Instantiate a new <see cref="ConnectResult"/> where the client got connected. /// <see cref="ConnectError"/> will be <see cref="ConnectError.Ok"/>. /// </summary> /// <param name="sessionState">The session state.</param> /// <param name="connectReturnCode">The connection return code.</param> public ConnectResult(SessionState sessionState, ConnectReturnCode connectReturnCode) { ConnectError = ConnectError.Ok; SessionState = sessionState; ConnectReturnCode = connectReturnCode; }
public ConnectFailedEventArgs(ConnectError reason) { Reason = reason; }