public void ConnectServer(string hostNameOrAddress, int port, TcpSocketInvokeElement invokeElement) { #if DEBUG_NETIO UnityEngine.Debug.Log(string.Format("Connect :{0} {1}", hostNameOrAddress, port)); #endif Interlocked.Exchange(ref tcpSocketState, 0); tcpClient.ConnectServer(hostNameOrAddress, port, invokeElement); }
public void ConnectServer(string hostNameOrAddress, int port, Action onConnectCompleted, Action <SocketError> onSocketError) { var invokeElement = new TcpSocketInvokeElement(); invokeElement.OnSocketCompleted = ConnectCompleted; invokeElement.OnSocketCompleted += onConnectCompleted; invokeElement.OnSocketError = onSocketError; ConnectServer(hostNameOrAddress, port, invokeElement); }
private bool Reconnect(TcpSocketUserToken userToken, TcpSocketInvokeElement invokeElement, int maxCount) { if (userToken.TcpSocket != null) { if (Interlocked.Exchange(ref tcpSocketState, -1) != -1) { if (maxCount > 0 && reconnectCount >= maxCount) { return(false); } if (!(!userToken.TcpSocket.Connected || (userToken.TcpSocket.Poll(1000, SelectMode.SelectRead) && (userToken.TcpSocket.Available == 0)))) { UnityEngine.Debug.LogWarning("Reconnect --> TcpSocket is Connected"); ReconnectCompleted(); // invokeElement.SocketCompletedInvoke(userToken); SendMsgPacket(); } else { UnityEngine.Debug.LogWarning("Reconnect --> TcpSocket is not Connected"); // invokeElement.ClearSendMsgPool(); if (heartbeatTread != null) { heartbeatTread.Abort(); } reconnectCount++; tcpClient.ReconnectSocket(invokeElement); } } return(true); } return(false); }
public bool RetryReconnect(TcpSocketInvokeElement invokeElement) { Interlocked.Exchange(ref tcpSocketState, -2); return(Reconnect(tcpClient.UserToken, invokeElement, 0)); }
public bool TryReconnect(TcpSocketUserToken userToken, TcpSocketInvokeElement invokeElement, int maxCount = 1) { return(Reconnect(userToken, invokeElement, maxCount)); }