Ejemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="read"></param>
 /// <param name="data"></param>
 public void OnReceive(SocketRead read, byte[] data)
 {
     //we got a screen shot from the pc
     Debug.Log("OnReceive() event fired.  bytes read " + data.Length);
     bytImagedata = data;
     blnGotNewImage = true;
 }
Ejemplo n.º 2
0
    void OnClientConnect(System.IAsyncResult result)
    {
        Debug.Log("Handling client connecting");

        try
        {
            //gameObject.SendMessage ("OnClientConnected", socket.EndAccept (result));
            Debug.Log("Client connected");
            Socket client = socket.EndAccept(result);
            clients.Add(client);
            SocketRead.Begin(client, OnReceive, OnReceiveError);
        }
        catch (System.Exception e)
        {
            Debug.Log("Exception when accepting incoming connection: " + e);
            Debug.LogError("Exception when accepting incoming connection: " + e);
        }

        try
        {
            socket.BeginAccept(new System.AsyncCallback(OnClientConnect), socket);
        }
        catch (System.Exception e)
        {
            Debug.LogError("Exception when starting new accept process: " + e);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="read"></param>
    /// <param name="data"></param>
    public void OnReceive(SocketRead read, byte[] data)
    {
        //Debug.Log("OnReceive() event fired. data size " + data.Length);
        string strHex = ByteArrayUtilities.ByteArrayToString(data);
        //Debug.Log("Hex : " + strHex);

        //Debug.Log("process Java controller data ");
        VRUtilities.DecodeControllerData(data, ref cntlMsgs);
        //Debug.Log("Controller Messages " + cntlMsgs.ToString());

        //make sure we only set the resolution once
        if (blnGotDeviceResolution == false)
        {
            //check to see if the device gave us its dimensions. if so, use them instead of the default
            if (cntlMsgs.OptionMessage.ScreenHeight > 0 && cntlMsgs.OptionMessage.ScreenWidth > 0)
            {
                intDeviceScreenWidth = cntlMsgs.OptionMessage.ScreenWidth;
                intDeviceScreenHeight = cntlMsgs.OptionMessage.ScreenHeight;

                intDeviceScreenWidth = TextureUtilities.getSquare(intDeviceScreenWidth, TextureUtilities.sqSquareType.lowest);
                intDeviceScreenHeight = TextureUtilities.getSquare(intDeviceScreenHeight, TextureUtilities.sqSquareType.lowest);

                blnGotDeviceResolution = true;
            }
        }
    }
    void OnClientStarted(Socket socket)
    {
        Debug.Log("Client started");

        this.socket = socket;
        SocketRead.Begin(socket, OnReceive, OnError);
    }
Ejemplo n.º 5
0
    private void OnReceive(SocketRead read, byte[] data)
    {
        //string message = "lServer: Client " + mClients.IndexOf(read.Socket) + " says: " + Encoding.ASCII.GetString(data, 0, data.Length);
        //mSocketDebug.DebugLog(message);

        string json = Encoding.ASCII.GetString(data, 0, data.Length);

        JSONNode jsonNode = JSON.Parse(json);

        mBatchedContent = jsonNode.AsArray;
    }
Ejemplo n.º 6
0
	void OnReceive (SocketRead read, byte[] data)
	{
		string message = "Client " + clients.IndexOf (read.Socket) + " says: " + Encoding.ASCII.GetString (data, 0, data.Length);
		Debug.Log (message);

		foreach (Socket client in clients)
		{
			if (client == read.Socket)
			{
				continue;
			}

			client.Send (Encoding.ASCII.GetBytes (message));
		}
	}
    void OnReceive(SocketRead read, byte[] data)
    {
        string message = "Client " + clients.IndexOf (read.Socket) + " says: " + Encoding.ASCII.GetString (data, 0, data.Length);
        Debug.Log (message);

        foreach (Socket client in clients)
        {
            if (client == read.Socket)
            {
                continue;
            }

            client.Send (Encoding.ASCII.GetBytes (message));
        }
    }
Ejemplo n.º 8
0
    void OnReceive(SocketRead read, byte[] data)
    {
        // Debug.Log("DataLength Array: " + data.Length);
        if (_complete && data.Length == 4) // laenge der msg wird in 4 bytes geschickt
        {
            _complete     = false;
            _bytesWritten = 0;
            _byteLength   = System.BitConverter.ToInt32(data, 0);
            if (_byteLength > 0)
            {
                _file = new byte[_byteLength];
            }

            ReportLengthDone();
        }
        else
        {
            if (!_wait)
            {
                try
                {
                    System.Array.Copy(data, 0, _file, _bytesWritten, data.Length);
                    _bytesWritten += data.Length;
                    // Debug.Log("bytesWritten: " + _bytesWritten + "bytesLength: " + _byteLength);
                }
                catch
                {
                    print("D Error: too many bytes for file received. Waiting for new beginning");
                    _wait = true;
                }
            }
        }
        if (!_wait)
        {
            if (_bytesWritten == _byteLength)
            {
                _savedImageFile = _file; // saves in new File avoiding red error questionmark, stays in previous texture
                _complete       = true;
                _shouldAssemble = true;
                ReportDone();
            }
        }
    }
Ejemplo n.º 9
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);
            }
        }
    }
Ejemplo n.º 10
0
    void OnReceive(SocketRead read, byte[] data)
    {
        string clientSaid = Encoding.ASCII.GetString(data, 0, data.Length);

        /*string toPrint = "SAID: ";
         * for (int i=0; i<clientSaid.Length; i++)
         *      toPrint = toPrint + ((int)clientSaid[i]).ToString() + ",";
         * Debug.Log(toPrint);*/

        string message = "Client " + clients.IndexOf(read.Socket) + " says: " + clientSaid;

        Debug.Log(message);
        //process the incoming text and store in the message queue
        clientSaid = bufferUnfinished + clientSaid;
        //Debug.Log("new message is " + clientSaid);
        bufferUnfinished = "";
        //did it end in a return?
        List <string> allCommands = new List <string>(clientSaid.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries));

        if (message[message.Length - 1] != '\n')
        {
            bufferUnfinished = allCommands[allCommands.Count - 1];
            allCommands.RemoveAt((allCommands.Count) - 1);
            Debug.Log(allCommands.Count);
        }
        foreach (String cmd in allCommands)
        {
            AIMessage a;
            try {
                a = AIMessage.fromString(cmd);
            }
            catch (Exception e)
            {
                Debug.Log("Could not parse message due to error. Skipping.");
                GlobalVariables.outgoingMessages.Add("ERR,formattingError\n");
                continue;
            }
            bodyInterface.messageQueue.Add(a);
            //Debug.Log("added to message queue: " + a.messageType.ToString() + ", " + a.stringContent);
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="read"></param>
    /// <param name="data"></param>
    public void OnReceive(SocketRead read, byte[] data)
    {
        //Debug.Log("OnReceived() fired bytes " + data.Length);
        VRUtilities.DecodeControllerData(data, ref controllerMessages);

        //make sure we only set the resolution once
        if (blnGotDeviceResolution == false)
        {
            //check to see if the device gave us its dimensions. if so, use them instead of the default
            if (controllerMessages.OptionMessage.ScreenHeight > 0 && controllerMessages.OptionMessage.ScreenWidth > 0)
            {
                intDeviceScreenWidth = controllerMessages.OptionMessage.ScreenWidth;
                intDeviceScreenHeight = controllerMessages.OptionMessage.ScreenHeight;

                intDeviceScreenWidth = TextureUtilities.getSquare(intDeviceScreenWidth, TextureUtilities.sqSquareType.lowest);
                intDeviceScreenHeight = TextureUtilities.getSquare(intDeviceScreenHeight, TextureUtilities.sqSquareType.lowest);

                blnGotDeviceResolution = true;
            }
        }
    }
Ejemplo n.º 12
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);
            }
        }
    }
Ejemplo n.º 13
0
 private void OnReceive(SocketRead read, byte[] data)
 {
     mSocketDebug.DebugLog("lClient: OnReceive");
     mSocketDebug.DebugLog(Encoding.ASCII.GetString(data, 0, data.Length));
 }
Ejemplo n.º 14
0
 void OnReceiveError(SocketRead read, System.Exception exception)
 {
     Debug.LogError("Receive error: " + exception);
 }
Ejemplo n.º 15
0
 private void OnReceiveError(SocketRead read, System.Exception exception)
 {
     mSocketDebug.DebugLogError("lServer: Receive error: " + exception);
 }
Ejemplo n.º 16
0
 void OnClientConnected(Socket client)
 {
     Debug.Log("Client connected");
     clients.Add(client);
     SocketRead.Begin(client, OnReceive, OnReceiveError);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="read"></param>
 /// <param name="exception"></param>
 public void OnReceiveError(SocketRead read, System.Exception exception)
 {
     Debug.Log("OnReceiveError() event fired");
     Debug.Log(exception.ToString());
 }
Ejemplo n.º 18
0
 void OnError(SocketRead read, System.Exception exception)
 {
     Debug.LogError ("Receive error: " + exception);
 }
Ejemplo n.º 19
0
 void OnReceive(SocketRead read, byte[] data)
 {
     Debug.Log (Encoding.ASCII.GetString (data, 0, data.Length));
 }
Ejemplo n.º 20
0
    private void OnReceive(SocketRead read, byte[] data)
    {
        //string message = "lServer: Client " + mClients.IndexOf(read.Socket) + " says: " + Encoding.ASCII.GetString(data, 0, data.Length);
        //mSocketDebug.DebugLog(message);

        string json = Encoding.ASCII.GetString(data, 0, data.Length);

        JSONNode jsonNode = JSON.Parse(json);

        mBatchedContent = jsonNode.AsArray;
    }
Ejemplo n.º 21
0
 private void OnReceiveError(SocketRead read, System.Exception exception)
 {
     mSocketDebug.DebugLogError("lServer: Receive error: " + exception);
 }
Ejemplo n.º 22
0
 public void OnClientStartedAnswer(Socket socket)
 {
     //  Debug.Log("CLient Answer started");
     this.socketAnswer = socket;
     SocketRead.Begin(socket, OnReceive, OnError);
 }
Ejemplo n.º 23
0
 public void OnClientStartedTouch(Socket socket)
 {
     //  Debug.Log("CLient Touch started");
     this.socketTouch = socket;
     SocketRead.Begin(socket, OnReceive, OnError);
 }
Ejemplo n.º 24
0
 private void OnReceive(SocketRead read, byte[] data)
 {
     mSocketDebug.DebugLog("lClient: OnReceive");
     mSocketDebug.DebugLog(Encoding.ASCII.GetString(data, 0, data.Length));
 }
Ejemplo n.º 25
0
 private void OnError(SocketRead read, System.Exception exception)
 {
     mSocketDebug.DebugLogError("lClient: Receive error: " + exception);
 }
Ejemplo n.º 26
0
 private void OnError(SocketRead read, System.Exception exception)
 {
     mSocketDebug.DebugLogError("lClient: Receive error: " + exception);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="read"></param>
 /// <param name="exception"></param>
 void OnReceiveError(SocketRead read, System.Exception exception)
 {
     Debug.LogError ("Receive error: " + exception);
     if (SocketServerHandler != null) SocketServerHandler.OnReceiveError(read, exception);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="read"></param>
 /// <param name="data"></param>
 void OnReceive(SocketRead read, byte[] data)
 {
     Debug.Log("message size = " + data.Length);
     if (SocketServerHandler != null) SocketServerHandler.OnReceive(read, data);
 }
 void OnReceive(SocketRead read, byte[] data)
 {
     Debug.Log(Encoding.ASCII.GetString(data, 0, data.Length));
 }
Ejemplo n.º 30
0
    void OnReceive(SocketRead read, byte[] data)
    {
        string clientSaid = Encoding.ASCII.GetString (data, 0, data.Length);

        /*string toPrint = "SAID: ";
        for (int i=0; i<clientSaid.Length; i++)
            toPrint = toPrint + ((int)clientSaid[i]).ToString() + ",";
        Debug.Log(toPrint);*/

        string message = "Client " + clients.IndexOf (read.Socket) + " says: " + clientSaid;
        Debug.Log (message);
        //process the incoming text and store in the message queue
        clientSaid = bufferUnfinished + clientSaid;
        //Debug.Log("new message is " + clientSaid);
        bufferUnfinished = "";
        //did it end in a return?
        List<string> allCommands = new List<string>(clientSaid.Split(new char[]{'\n'}, StringSplitOptions.RemoveEmptyEntries));
        if (message[message.Length-1] != '\n')
        {
            bufferUnfinished = allCommands[allCommands.Count-1];
            allCommands.RemoveAt((allCommands.Count)-1);
            Debug.Log (allCommands.Count);
        }
        foreach (String cmd in allCommands)
        {
            AIMessage a;
            try {
                a = AIMessage.fromString(cmd);
            }
            catch(Exception e)
            {
                Debug.Log("Could not parse message due to error. Skipping.");
                GlobalVariables.outgoingMessages.Add("ERR,formattingError\n");
                continue;
            }
            bodyInterface.messageQueue.Add(a);
            //Debug.Log("added to message queue: " + a.messageType.ToString() + ", " + a.stringContent);
        }
    }