private void serverThread() { try{ _tcpListener = new TcpListener(IPAddress.Any, _port); printS("Listening for connection..."); _tcpListener.Start(); _tcpClient = _tcpListener.AcceptTcpClient(); NetworkStream stream = _tcpClient.GetStream(); cb?.Invoke("Client Connected"); Byte[] bytes = new byte[16]; while (true) { int length; if (stream.DataAvailable) { stream.Read(bytes, 0, 16); NetPacket np = new NetPacket(); np.setHeaderFromBArr(bytes); _squeue.enqueue(np); printS(np.ToString()); } } } catch (SocketException e) { printS(e.ToString()); } }
private void clientThread() { try{ socketConnection = new TcpClient("localhost", _port); cb?.Invoke("Connected to host"); NetworkStream stream = socketConnection.GetStream(); Byte[] bytes = new byte[16]; while (true) { int length; // If we have data attempt to read the first 4 bytes to get the size of the whole packet we will be reading if (stream.DataAvailable) { stream.Read(bytes, 0, 16); NetPacket np = new NetPacket(); np.setHeaderFromBArr(bytes); _squeue.enqueue(np); printS(np.ToString()); } } } catch (SocketException e) { printS(e.ToString()); } }
//! is called from the SahredStateManager when the entry got changed from the server public void update(MessageBuffer mb) { deserializeValue(mb); if (cb != null) { cb.Invoke(); } }
IEnumerator JSONRequest(string path, WWWForm variables, callBack callBack) { WWW urlRequest = new WWW(path, variables); yield return(urlRequest); //Wait on url request to come back to us before proceeding string jsonFileString = urlRequest.text; callBack.Invoke(jsonFileString); }