Example #1
0
    private void OnReceive(IAsyncResult ar)
    {
        try
        {
            int    byteAmt = myStream.EndRead(ar);
            byte[] myBytes = new byte[byteAmt];
            Buffer.BlockCopy(asyncBuff, 0, myBytes, 0, byteAmt);
            if (byteAmt == 0)
            {
                return;
            }

            UnityThread.executeInUpdate(() =>
            {
                ClientHandleData.HandleData(myBytes);
            });
            myStream.BeginRead(asyncBuff, 0, 8192, OnReceive, null);
        }
        catch
        {
            Debug.LogError("Connection to Server " + currentIP + ":" + currentPort + " Was Lost.");
            currentIP   = string.Empty;
            currentPort = -1;
            connected   = false;
            connecting  = false;
            //NetworkManager.DestroyAllPlayers();
        }
    }
Example #2
0
        //If the Welcome Message arrives
        //it begins to endless loop all other Messages in different Unity Thread
        private static void ReceiveCallback(IAsyncResult result)
        {
            try
            {
                int length = myStream.EndRead(result);
                if (length <= 0)
                {
                    return;
                }


                byte[] newBytes = new byte[length];
                Array.Copy(recBuffer, newBytes, length);
                UnityThread.executeInFixedUpdate(() =>
                {
                    ClientHandleData.HandleData(newBytes);
                });
                //Infinte Loop
                myStream.BeginRead(recBuffer, 0, 4096 * 2, ReceiveCallback, null);
            }

            catch (Exception)
            {
                //NetworkManager.instance.DestroyLocalPlayer();
                return;
            }
        }
Example #3
0
    private static void ReceiveCallback(IAsyncResult ar)
    {
        try
        {
            int readBytes = myStream.EndRead(ar);

            if (readBytes <= 0)
            {
                return;
            }

            byte[] newBytes = new byte[readBytes];
            Buffer.BlockCopy(asyncBuffer, 0, newBytes, 0, readBytes);

            // Add Unity Thread Here
            UnityThread.executeInUpdate(() =>
            {
                // HandleData here
                ClientHandleData.HandleData(newBytes);
            });

            myStream.BeginRead(asyncBuffer, 0, Constants.MAX_BUFFERSIZE * 2, ReceiveCallback, null);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
Example #4
0
    private static void ReceiveCallback(IAsyncResult result)
    {
        try
        {
            int readBytes = myStream.EndRead(result);
            if (readBytes <= 0)
            {
                return;
            }

            byte[] newBytes = new byte[readBytes];
            Buffer.BlockCopy(receiveBuffer, 0, newBytes, 0, readBytes);

            UnityThread.executeInUpdate(() =>
            {
                ClientHandleData.HandleData(newBytes);
            });

            myStream.BeginRead(receiveBuffer, 0, 4096 * 2, ReceiveCallback, null);
        }
        catch (Exception)
        {
            throw;
        }
    }
 void Start()
 {
     DontDestroyOnLoad(this);
     UnityThread.initUnityThread();
     ClientHandleData.InitializePackets();
     ClientTCP.InitializingNetworking();
 }
Example #6
0
 private void Start()
 {
     UnityThread.initUnityThread();
     ClientHandleData.InitializePackets();
     InitializeNetwork();
     //ClientTCP.InitializeNetworking();
 }
Example #7
0
    private static void ReceiveCallback(IAsyncResult result)
    {
        try
        {
            int readByteSize = _clientNetworkStream.EndRead(result);
            if (readByteSize <= 0)
            {
                return;
            }
            byte[] newBytes = new byte[readByteSize];
            Buffer.BlockCopy(_asyncBuffer, Constants.NETWORK_STREAM_OFFSET, newBytes, Constants.NETWORK_STREAM_OFFSET, readByteSize);

            //Add unity thread here
            UnityThread.executeInUpdate(() =>
                                        //Hanlde data here
                                        ClientHandleData.HandleData(newBytes)
                                        );
            _clientNetworkStream.BeginRead(_asyncBuffer, Constants.NETWORK_STREAM_OFFSET, Constants.MAX_BUFFER_SIZE * 2, ReceiveCallback, null);
        }
        catch (ArgumentException ex)
        {
            Debug.Log("ClientConnectCallback error: " + ex.Message);
            return;
        }
    }
 void Start()
 {
     Debug.Log("Customnetworkmanager Start");
     DontDestroyOnLoad(this);
     MainThreadDispatcher.Initialize();
     ClientHandleData.InitializePackets();
     ClientTCP.InitializingNetworking();
 }
Example #9
0
    // Start is called before the first frame update
    public void initiate()
    {
        DontDestroyOnLoad(this);
        UnityThread.initUnityThread();

        ClientHandleData.InizializzaPacchetti();
        ClientTcp.InizializzaNetwork();
    }
Example #10
0
    private void Awake()
    {
        DontDestroyOnLoad(this);
        UnityThread.initUnityThread();

        ClientHandleData.InitializePacketListener();
        ClientTCP.InitializeClientSocket(ipAddress, port);
    }
Example #11
0
 private void Awake()
 {
     instance = this;
     DontDestroyOnLoad(this);
     UnityThread.initUnityThread();
     InitPlayers();
     ClientHandleData.InitPackets();
     ClientTCP.InitClient(IPAddress, Port);
 }
    private void Awake()
    {
        // This two methods for working with TCP in Unity Thread
        DontDestroyOnLoad(this);
        UnityThread.initUnityThread();

        //Connection
        ClientHandleData.InitializePacketListener();
        ClientTCP.InitializeClientSocket(ipAddress, port);
    }
Example #13
0
    private void Awake()
    {
        instance    = this;
        host        = "localhost";
        port        = 7171;
        isConnected = false;
        DontDestroyOnLoad(this);
        UnityThread.initUnityThread();

        ClientHandleData.InitializePacketListener();
        ClientTCP.InitializeClientSocket(host, port);
    }
 //If the User presses the Connect Button, he will get to this Method
 //It checks if the writen Username is valid
 //It also starts connecting to the Server
 public void ConnectToServer()
 {
     StartMenuUI.instanceUI.ClearAllErrors();
     if (!(StartMenuUI.instanceUI.IsUsernameVaild()))
     {
         return;
     }
     if (alreadyTriedToConnect)
     {
         ClientTCP.InitializingNetworking();
     }
     else
     {
         alreadyTriedToConnect = true;
         ClientHandleData.InitializePackets();
         ClientTCP.InitializingNetworking();
     }
 }
Example #15
0
 private static void ReceiveCallback(IAsyncResult result)
 {
     try
     {
         int length = myStream.EndRead(result);
         if (length < 0)
         {
             return;
         }
         Debug.Log("receive");
         byte[] newBytes = new byte[length];
         Array.Copy(recBuffer, newBytes, length);
         Scheduler.MainThreadFixedUpdate.Schedule(() => ClientHandleData.HandleData(newBytes));
         myStream.BeginRead(recBuffer, 0, 4092 * 2, ReceiveCallback, null);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #16
0
    private static void ReceiveCallback(IAsyncResult result)
    {
        try
        {
            int length = myStream.EndRead(result);
            if (length <= 0)
            {
                return;
            }

            byte[] newBytes = new byte[length];
            Array.Copy(recBuffer, newBytes, length);
            UnityThread.executeInFixedUpdate(() =>
            {
                ClientHandleData.HandleData(newBytes);
            });
        }
        catch (Exception)
        {
            throw;
        }
    }
Example #17
0
    private void OnReceive(IAsyncResult ar)
    {
        try
        {
            int    byteAmt = myStream.EndRead(ar);
            byte[] myBytes = new byte[byteAmt];
            Buffer.BlockCopy(asyncBuff, 0, myBytes, 0, byteAmt);
            if (byteAmt == 0)
            {
                return;
            }

            UnityThread.executeInUpdate(() =>
            {
                ClientHandleData.HandleData(myBytes);
            });
            myStream.BeginRead(asyncBuff, 0, playerSocket.SendBufferSize, OnReceive, null);
        }
        catch
        {
        }
    }
Example #18
0
 public static void ReceiveCallBack(IAsyncResult result)
 {
     try
     {
         int lenght = stream.EndRead(result);
         if (lenght <= 0)
         {
             return;
         }
         byte[] newBytes = new byte[lenght];
         Array.Copy(recBuffer, newBytes, lenght);
         UnityThread.executeInFixedUpdate(() =>
         {
             ClientHandleData.HandleData(newBytes);
         });
         stream.BeginRead(recBuffer, 0, sizeBuffer * 2, ReceiveCallBack, null);
     }
     catch (Exception)
     {
         //throw;
     }
 }
Example #19
0
    private static void ReceiveCallback(IAsyncResult result)
    {
        try
        {
            int lenght = myStream.EndRead(result);
            if (lenght <= 0)
            {
                return;
            }

            byte[] newBytes = new byte[lenght];
            Array.Copy(recBuffer, newBytes, lenght);
            UnityThread.executeInFixedUpdate(() =>
            {
                ClientHandleData.HandleData(newBytes);
            });
            myStream.BeginRead(recBuffer, 0, 4096 * 2, ReceiveCallback, null);
        }
        catch (Exception)
        {
            Disconnect();
            return;
        }
    }
Example #20
0
 private void Awake()
 {
     instance = this;
 }
 private void Awake()
 {
     instance = this;
     InitMessages();
 }
Example #22
0
 static void Main(string[] args)
 {
     InitializeConsoleThread();
     ClientHandleData.InitializePacketListener();
     ClientTCP.InitializeClientSocket("34.72.41.136", 19132);
 }
Example #23
0
 public void StartConnection()
 {
     ClientHandleData.InitializePackets();
     ClientTCP.ServerAddress = serverAddress;
     ClientTCP.InitializingNetworking();
 }