Example #1
0
    private void OnConnectCallBack(IAsyncResult ar)
    {
        SDebug.Log(string.Format("Connect {0}({1}) {2}", _type, _lep, _socket.Connected ? "Success" : "Faild"));
        if (!_socket.Connected)
        {
            _curState = SocketState.connectFaild;
            return;
        }

        _socket.EndConnect(ar);
        _curState = SocketState.connected;
    }
Example #2
0
    static void ReBuild()
    {
        _process = new Process();
        _process.StartInfo.FileName               = _curPath + _fileName;
        _process.StartInfo.UseShellExecute        = false;
        _process.StartInfo.RedirectStandardOutput = true;
        _process.StartInfo.RedirectStandardError  = true;
        _process.StartInfo.CreateNoWindow         = true;

        DirectoryInfo info = new DirectoryInfo(_protoFilePath);

        WalkDirectoryTree(info, "");
        SDebug.Log("Protobuf ReBuild All Completed");
    }
Example #3
0
 private void Connect()
 {
     /* 不使用同步Connect的原因
      * 同步的Connect会Block当前线程
      * 可能会出现在尝试Connect的过程中(无网络),长时间Block当前线程
      * 且TCP类型的Connect无法设置为非Block
      */
     try {
         _socket.BeginConnect(_lep, OnConnectCallBack, _socket);
         _curState        = SocketState.connecting;
         _lastConnectTime = Time.realtimeSinceStartup;
     } catch (SocketException e) {
         SDebug.Log(e.ToString());
         SDebug.Log("ErrorCode: ", e.ErrorCode);
         _curState = SocketState.connectFaild;
     } catch (Exception e) {
         SDebug.Log(e.ToString());
         _curState = SocketState.connectFaild;
     }
 }
Example #4
0
    private void CloseSocket()
    {
        if (_socket != null)
        {
            try {
                if (_socket.Connected)
                {
                    _socket.Shutdown(SocketShutdown.Both);
                }

                _socket.Close();
            } catch (SocketException e) {
                SDebug.Log(e.ToString());
                SDebug.Log("ErrorCode: ", e.ErrorCode);
            } catch (Exception e) {
                SDebug.Log(e.ToString());
            }

            _socket = null;
        }
    }