Ejemplo n.º 1
0
    /**
     * 建立连接。
     *
     * @throws Exception
     */
    public static ZealmSocketConnection createConnection(String url)
    {
        // 建立Socket连接。
        if (connection == null)
        {
            try
            {
                string[] strAdd = url.Split(':');
                string   urlAdd = strAdd[0];
                int      port   = int.Parse(strAdd[1]);
                connection = new ZealmSocketConnection(urlAdd, port);
                connection.start();

                if (!TableRead.my.Equals(null))
                {
                    TableRead.my.strInfo = StaticLoc.Loc.Get("meg0099");
                }
            }
            catch (Exception e)
            {
                if (!TableRead.my.Equals(null))
                {
                    TableRead.my.strInfo       = StaticLoc.Loc.Get("meg0098");
                    TableRead.my.isConnectFail = true;
                }
                MonoBehaviour.print(string.Format("IP:{0},{1}", url, e.ToString()));
            }
        }

        return(connection);
    }
Ejemplo n.º 2
0
 /**
  * 向服务器发送请求。
  *
  * @param segment 发送的包。
  */
 public static void sendRequest(ZMNetData netData)
 {
     if (connection != null)
     {
         ZealmSocketConnection.writeNetData(netData);
     }
     else
     {
         MonoBehaviour.print("==============warning: connection is null. request not sent");
     }
 }
Ejemplo n.º 3
0
    public void run()
    {
        MonoBehaviour.print("ZealmSocketConnection run()");
        if (parent == null)
        {
            _reader = new ZealmSocketConnection(this, (byte)0);
            new Thread(new ThreadStart(_reader.run)).Start();

            _writer = new ZealmSocketConnection(this, (byte)1);
            new Thread(new ThreadStart(_writer.run)).Start();
        }
        else if (runType == (byte)0)
        {
            runReader();
        }
        else
        {
            runWriter();
        }
    }
Ejemplo n.º 4
0
    public void close()
    {
        IsConnected = false;

        if (_reader != null)
        {
            try
            {
                _reader.close();
            }
            catch (IOException ex2)
            {
            }
        }

        if (_writer != null)
        {
            try
            {
                _writer.close();
            }
            catch (IOException ex3)
            {
            }
        }



        _reader = null;
        _writer = null;
        if (netStream != null)
        {
            netStream.Close();
        }
        if (tcpClient != null)
        {
            tcpClient.Close();
        }
    }
Ejemplo n.º 5
0
    /**
     * 关闭连接。
     */
    public static void closeConnection()
    {
        string stackInfo = new StackTrace().ToString();

//        KDebug.WriteLog("=========================closeConnection========================" + stackInfo);
        if (connection != null)
        {
            try
            {
                ZealmSocketConnection temp = connection;
                connection       = null;
                temp.IsConnected = false;
                temp.close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        System.GC.Collect();
    }
Ejemplo n.º 6
0
 public ZealmSocketConnection(ZealmSocketConnection par, byte rt)
 {
     parent  = par;
     runType = rt;
 }