コード例 #1
0
 private void Start()
 {
     mSocketDebug = GetComponent <SocketDebug>();
     if (Host(kPort))
     {
         mSocketDebug.DebugLog("lServer: started");
     }
 }
コード例 #2
0
    public void Update()
    {
        if (OnClientConnectResult != null)
        {
            mSocketDebug.DebugLog("lServer: Handling client connecting");
            try
            {
                Socket client = mSocket.EndAccept(OnClientConnectResult);

                mSocketDebug.DebugLog("lServer: Client connected");
                mClients.Add(client);
                SocketRead.Begin(client, OnReceive, OnReceiveError);
                OnClientConnectResult = null;
            }
            catch (System.Exception e)
            {
                mSocketDebug.DebugLogError("lServer: Exception when accepting incoming connection: " + e);
            }

            try
            {
                mSocket.BeginAccept(new System.AsyncCallback(OnClientConnect), mSocket);
            }
            catch (System.Exception e)
            {
                mSocketDebug.DebugLogError("lServer: Exception when starting new accept process: " + e);
            }
        }

        if (mBatchedContent.Count > 0)
        {
            foreach (JSONData transaction in mBatchedContent)
            {
                Debug.Log(transaction.ToString());
            }

            while (mBatchedContent.Count > 0)
            {
                mBatchedContent.Remove(0);
            }
        }
    }
コード例 #3
0
    public void Update()
    {
        if (!mSocket.Connected)
        {
            mSocketDebug.DebugLog("lClient: Connecting...");

            try
            {
                mSocket.Connect(new IPEndPoint(IP, kPort));
            }
            catch (System.Exception e)
            {
                mSocketDebug.DebugLogError("lClient: Exception: " + e.Message);
                mSocketDebug.DebugLogError("lClient: Failed to connect to " + ip + " on port " + kPort);
            }

            if (mSocket.Connected)
            {
                mSocketDebug.DebugLog("lClient: Successfully connected to " + ip + " on port " + kPort);
                mSocketDebug.DebugLog("lClient: started");
                SocketRead.Begin(mSocket, OnReceive, OnError);
            }
        }
    }
コード例 #4
0
 private void Start()
 {
     mSocketDebug = GetComponent<SocketDebug>();
     if (Host(kPort))
     {
         mSocketDebug.DebugLog("lServer: started");
     }
 }