コード例 #1
0
ファイル: Session.cs プロジェクト: uglyduck68/gamnet
        public void Connect(string host, int port, int timeout_sec = 60)
        {
            try {
                lock (_sync_obj) {
                    _send_queue_idx = 0;
                    _send_queue.Clear();
                }
                _host = host;
                _port = port;
                _networkReachability = Application.internetReachability;
                _timeout_monitor     = new TimeoutMonitor();
                _socket          = null;
                _endpoint        = null;
                _timer           = null;
                _send_seq        = 0;
                _recv_seq        = 0;
                _state           = ConnectionState.OnConnecting;
                _connect_timeout = timeout_sec * 1000;

                SetEndPoint(host, port);

                Socket socket = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                //Debug.Log(LogHeader.Function + "socket.BeginConnect(_endpoint, new AsyncCallback(Callback_Connect), socket);");
                socket.BeginConnect(_endpoint, new AsyncCallback(Callback_Connect), socket);
                //Debug.Log(LogHeader.Function + "SetConnectTimeout");
                SetConnectTimeout();
            }
            catch (SocketException e) {
                Debug.LogError("[Session.Connect] host:" + host + ", port:" + port + ", timeout_sec:" + timeout_sec + ", exception:" + e.ToString());
                Error(new Gamnet.Exception(ErrorCode.ConnectFailError, e.ToString()));
            }
        }
コード例 #2
0
        public void Connect(string host, int port, int timeout_sec = 10)
        {
            try
            {
                lock (this)
                {
                    _send_queue_idx = 0;
                    _send_queue.Clear();

                    _networkReachability = Application.internetReachability;
                    _timeout_monitor     = new TimeoutMonitor();
                    _socket          = null;
                    _endpoint        = null;
                    _timer           = null;
                    _send_seq        = 0;
                    _recv_seq        = 0;
                    _state           = ConnectionState.OnConnecting;
                    _connect_timeout = timeout_sec * 1000;

                    IPAddress ip = null;
                    try
                    {
                        ip = IPAddress.Parse(host);
                    }
                    catch (System.FormatException)
                    {
                        IPHostEntry hostEntry = Dns.GetHostEntry(host);
                        if (hostEntry.AddressList.Length > 0)
                        {
                            ip = hostEntry.AddressList[0];
                        }
                    }
                    _endpoint = new IPEndPoint(ip, port);

                    Socket socket = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                    socket.BeginConnect(_endpoint, new AsyncCallback(Callback_Connect), socket);
                    SetConnectTimeout();
                }
            }
            catch (SocketException e)
            {
                Debug.LogError("[Session.Connect] host:" + host + ", port:" + port + ", timeout_sec:" + timeout_sec + ", exception:" + e.ToString());
                Error(new Gamnet.Exception(ErrorCode.ConnectFailError, e.ToString()));
            }
        }
コード例 #3
0
        public void Connect(string host, int port, int timeout_sec = 60)
        {
            try {
                lock (_sync_obj) {
                    _send_queue_idx = 0;
                    _send_queue.Clear();
                }

                _networkReachability = Application.internetReachability;
                _timeout_monitor     = new TimeoutMonitor();
                _socket          = null;
                _endpoint        = null;
                _timer           = null;
                _msg_seq         = 0;
                _state           = ConnectionState.OnConnecting;
                _connect_timeout = timeout_sec * 1000;

                IPAddress ip = null;
                try {
                    ip = IPAddress.Parse(host);
                }
                catch (System.FormatException) {
                    IPHostEntry hostEntry = Dns.GetHostEntry(host);
                    if (hostEntry.AddressList.Length > 0)
                    {
                        ip = hostEntry.AddressList[0];
                    }
                }
                _endpoint = new IPEndPoint(ip, port);

                Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                socket.BeginConnect(_endpoint, new AsyncCallback(Callback_Connect), socket);
                SetConnectTimeout();
            }
            catch (SocketException e) {
                Error(new Gamnet.Exception(ErrorCode.UndefinedError, e.Message));
            }
        }
コード例 #4
0
ファイル: StreamSession.cs プロジェクト: codingsf/gamnet
 public StreamSession()
 {
     timeoutMonitor = new TimeoutMonitor(this);
 }