// Start is called before the first frame update
    void Start()
    {
        AppFacade.Instance.StartUp();
        NetWorkMgr networkMgr = AppFacade.Instance.GetManager <NetWorkMgr>(ManagerName.NetWorkMgr);

        sock = networkMgr.CreateTcpSocket(new TConfig()
        {
            ip = ip, name = "TSocketDemo", port = port
        }, this);
        sock.Start();
    }
Beispiel #2
0
    /// <summary>
    /// 创建TCP对象接口
    /// </summary>
    /// <param name="config"></param>
    /// <param name="protocolType"></param>
    /// <param name="autoconnec"></param>
    /// <param name="autoConnecSecond"></param>
    /// <param name="bufferSize"></param>
    /// <returns></returns>
    public TSock CreateTcpSocket(TConfig config, ISocketMessage socketMessage, bool autoconnec = true, int autoConnecSecond = 1000, int bufferSize = 1024)
    {
        TSock sock = new TSock(config, socketMessage, ProtocolType.Tcp, autoconnec, autoConnecSecond, bufferSize);
        var   temp = tcpSockList.Find(m => m.tConfig.name.Equals(config.name));

        if (temp != null)
        {
            temp.Dispose();
            tcpSockList.Remove(temp);
        }
        tcpSockList.Add(sock);
        return(sock);
    }
Beispiel #3
0
    public bool Connect()
    {
        try
        {
            client = new TcpClient();

            client.Connect(serverEndPoint);

            nws = client.GetStream();
            TSock ts = new TSock(nws, this);
            t = new Thread(new ThreadStart(ts.process));
            t.IsBackground = true;
            t.Start();
            isConnected = true;
        }
        catch (Exception ex)
        {
            print(ex.Message + " : OnConnect");
        }
        if (client == null)
        {
            return(false);
        }


        //if(server.numOfClientsConnected = 2) playerThatClientControls = 2;
        //else playerThatClientControls = 1;
        //if(nws == 1)
        //		if(receiverBuffer.Dequeue ().ToString() == "1")
        //		{
        //			playerThatClientControls = 2;
        //		}
        //		else
        //		{
        //			playerThatClientControls = 1;
        //		}



        return(client.Connected);
    }
Beispiel #4
0
    public bool Connect()
    {
        try
        {

            client = new TcpClient();

            client.Connect(serverEndPoint);

            nws = client.GetStream();
            TSock ts = new TSock(nws, this);
            t = new Thread(new ThreadStart(ts.process));
            t.IsBackground = true;
            t.Start();
            isConnected = true;
        }
        catch (Exception ex)
        {
            print(ex.Message + " : OnConnect");

        }
        if (client == null) return false;

        //if(server.numOfClientsConnected = 2) playerThatClientControls = 2;
        //else playerThatClientControls = 1;
        //if(nws == 1)
        //		if(receiverBuffer.Dequeue ().ToString() == "1")
        //		{
        //			playerThatClientControls = 2;
        //		}
        //		else
        //		{
        //			playerThatClientControls = 1;
        //		}

        return client.Connected;
    }