public void Add(AsyncSocket tmp_Socket) { try { _socketCol.Add(tmp_Socket.SocketID, tmp_Socket); tmp_Socket.SocketDisconnected += SocketDisconnected; tmp_Socket.SocketDataArrival += SocketDataArrival; } catch (Exception ex) { throw ex; } }
private void m_ServerSocket_ConnectionAccept(AsyncSocket tmp_Socket) { try { Add(tmp_Socket); if (onConnectionAccept != null) { onConnectionAccept(tmp_Socket.SocketID); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Set socket /// </summary> /// <param name="socket"></param> /// <returns></returns> public bool SetSocket(AsyncSocket socket) { try { _socket = socket; _socket.CouldNotConnect += _socket_CouldNotConnect; _socket.SocketConnected += _socket_SocketConnected; _socket.SocketDataArrival += _socket_SocketDataArrival; _socket.SocketDisconnected += _socket_SocketDisconnected; return true; } catch (Exception ex) { throw ex; } }
public void Add(AsyncSocket tmp_Socket) { try { _socketCol.Add(tmp_Socket.SocketID, tmp_Socket); tmp_Socket.SocketDisconnected += SocketDisconnected; tmp_Socket.SocketDataArrival += SocketDataArrival; } catch (Exception ex) { if (SocketError != null) { SocketError(ex); } } }
/// <summary> /// Entry Point /// </summary> /// <param name="userId"></param> /// <param name="serverIp"></param> /// <param name="port"></param> public UserSocket(int userId, string description, string serverIp, int port, int connectionId) { try { Model = new ConnectionModel(); GlobalObjects.UserSockets.StopMonitoringAll(userId); Model.Monitoring = false; Model.Server = serverIp; Model.Port = port; Model.UserId = userId; Model.Description = description; Model.ConnectionId = connectionId; Socket = new AsyncSocket(); Socket.CouldNotConnect += Socket_CouldNotConnect; Socket.SocketConnected += Socket_SocketConnected; Socket.SocketDataArrival += Socket_SocketDataArrival; Socket.SocketDisconnected += Socket_SocketDisconnected; Socket.SocketError += Socket_SocketError; ConnectionsHelper.Update(Model); } catch (Exception ex) { if (ProcessError != null) { ProcessError(ex, "UserSocket"); } } }
/// <summary> /// Connection Accept /// </summary> /// <param name="tmp_Socket"></param> private void _server_ConnectionAccept(AsyncSocket tmp_Socket) { try { var user = new UserObject(); _users.Add(user); user.SetSocket(tmp_Socket); } catch (Exception ex) { if (ProcessError != null) { ProcessError(ex, "_server_ConnectionAccept"); } } }
private void _server_ConnectionAccept(AsyncSocket tmp_Socket) { try { var guid = AddUser(); if (!string.IsNullOrEmpty(guid)) { SetSocket(guid, tmp_Socket); } } catch (Exception ex) { throw ex; } }
public bool SetSocket(string guid, AsyncSocket socket) { if (_users.Where(u => u.GuidStr == guid).Count() != 0) { var user = _users.Where(u => u.GuidStr == guid).FirstOrDefault(); user.SetSocket(socket); return true; } else { return false; } }
/// <summary> /// Set socket /// </summary> /// <param name="socket"></param> /// <returns></returns> public bool SetSocket(AsyncSocket socket) { try { _socket = socket; _socket.CouldNotConnect += _socket_CouldNotConnect; _socket.SocketConnected += _socket_SocketConnected; _socket.SocketDataArrival += _socket_SocketDataArrival; _socket.SocketDisconnected += _socket_SocketDisconnected; _socket.SocketError += _socket_SocketError; UserModel = new Models.UserModel(); return true; } catch (Exception ex) { if (ProcessError != null) { ProcessError(ex, "SetSocket"); } return false; } }
/// <summary> /// Socket Error /// </summary> /// <param name="_ex"></param> private void Socket_SocketError(Exception _ex) { try { var b = false; if (_ex.Message.Contains("An established connection was aborted by the software in your host machine")) { b = true; } else if (_ex.Message.Contains("An existing connection was forcibly closed by the remote host")) { b = true; } if (b) { SocketDisconnected(); } else { Model.Connected = false; Socket = new AsyncSocket(); Socket.CouldNotConnect += Socket_CouldNotConnect; Socket.SocketConnected += Socket_SocketConnected; Socket.SocketDataArrival += Socket_SocketDataArrival; Socket.SocketDisconnected += Socket_SocketDisconnected; Socket.SocketError += Socket_SocketError; ConnectionsHelper.Update(Model); } } catch (Exception ex) { if (ProcessError != null) { ProcessError(ex, "Socket_SocketError"); } } }
/// <summary> /// Could not connect /// </summary> /// <param name="SocketID"></param> private void Socket_CouldNotConnect(string SocketID) { try { if (Model.Monitoring) { GlobalObjects.Users.SendSocket(Model.UserId, Model.Server + ":Socket_CouldNotConnect"); } Socket = new AsyncSocket(); Socket.CouldNotConnect += Socket_CouldNotConnect; Socket.SocketConnected += Socket_SocketConnected; Socket.SocketDataArrival += Socket_SocketDataArrival; Socket.SocketDisconnected += Socket_SocketDisconnected; Socket.SocketError += Socket_SocketError; Model.Connected = false; ConnectionsHelper.Update(Model); } catch (Exception ex) { if (ProcessError != null) { ProcessError(ex, "Socket_CouldNotConnect"); } } }
/// <summary> /// Disconnect /// </summary> public void Disconnect() { try { Socket.Close(); Socket = new AsyncSocket(); Socket.CouldNotConnect += Socket_CouldNotConnect; Socket.SocketConnected += Socket_SocketConnected; Socket.SocketDataArrival += Socket_SocketDataArrival; Socket.SocketDisconnected += Socket_SocketDisconnected; Socket.SocketError += Socket_SocketError; ConnectionsHelper.Update(Model); } catch (Exception ex) { if (ProcessError != null) { ProcessError(ex, "Disconnect"); } } }
private void ResetSocket() { this.UIThread(() => cmdConnect.Text = "Connect"); this.UIThread(() => cmdConnect.Enabled = true); this.UIThread(() => cmdDestroy.Enabled = false); this.UIThread(() => cmdList.Enabled = false); this.UIThread(() => cmdMonitor.Enabled = false); this.UIThread(() => cmdDisconnect.Enabled = false); this.UIThread(() => cmdSend.Enabled = false); this.UIThread(() => cmdCreate.Enabled = false); this.UIThread(() => cmdClose.Enabled = false); this.UIThread(() => cmdAuth.Enabled = false); this.UIThread(() => cmdStopMonitoring.Enabled = false); this.UIThread(() => cmd_Connect.Enabled = false); this.UIThread(() => cmdRegister.Enabled = false); this.UIThread(() => cmdEmailVerify.Enabled = false); System.Threading.Thread.Sleep(200); _socket = new AsyncSocket(); _socket.CouldNotConnect += _socket_CouldNotConnect; _socket.SocketConnected += _socket_SocketConnected; _socket.SocketDataArrival += _socket_SocketDataArrival; _socket.SocketDisconnected += _socket_SocketDisconnected; }
private void Form1_Load(object sender, EventArgs e) { _socket = new AsyncSocket(); _socket.CouldNotConnect += _socket_CouldNotConnect; _socket.SocketConnected += _socket_SocketConnected; _socket.SocketDataArrival += _socket_SocketDataArrival; _socket.SocketDisconnected += _socket_SocketDisconnected; _socket.SocketError += _socket_SocketError; }