Exemple #1
0
        private void OpenSocket()
        {
            SocketConfig config = GetConfig();

            if (config == null)
            {
                Debugger.LogError("No NetworkConfig, Connect Failed.");
                return;
            }
            switch (config.type)
            {
            case Config.NetworkType.TCP:
                IPAddress[] addr           = Dns.GetHostAddresses(config.host);
                var         clientEndPoint = new IPEndPoint(addr[0], config.port);
                m_socket = new Socket(addr[0].AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                m_socket.Connect(clientEndPoint);
                if (m_socket.Connected)
                {
                    OnConnected(true);
                }
                else
                {
                    Debug.Log("Socket Connected Failed!");
                }
                break;
            }
        }
Exemple #2
0
        public void SetConfig(string host, int port, int type, int blockSize, int connectedTimeout, int loopTime, int pipelineTime, int heartBeatTime)
        {
            SocketConfig config = new SocketConfig(host, port, type, blockSize, connectedTimeout, loopTime, pipelineTime, heartBeatTime);

            m_Config = config;
        }