public void BeginCamDiscovery() { Debug.Log("Discovering stream.."); byte[] msg = NetworkHelper.CreateDatagram(PacketType.CAM_DISCOVERY, null); udpClient.Send(msg, msg.Length, broadcastAddr); discoveryingStream = true; }
public void BeginDiscovery() { if (!pipConnected) { currentMsg = "Discovering headset.."; byte[] msg = NetworkHelper.CreateDatagram(PacketType.PIP_DISCOVERY, null); udpClient.Send(msg, msg.Length, broadcastAddr); } }
private void SendGyroData() { byte[] msg = Encoding.ASCII.GetBytes(Input.gyro.attitude.x.ToString() + ":" + Input.gyro.attitude.y.ToString() + ":" + Input.gyro.attitude.z.ToString() + ":" + Input.gyro.attitude.w.ToString()); msg = NetworkHelper.CreateDatagram(PacketType.PIP_GYRODATA, msg); udpClient.Send(msg, msg.Length, targetAddr); }
void OnApplicationQuit() { if (tcpClient != null) { tcpClient.Close(); } if (pipConnected) { byte[] msg = NetworkHelper.CreateDatagram(PacketType.PIP_DISCONNECT, null); udpClient.Send(msg, msg.Length, pipAddr); } udpClient.Close(); }
public void StartPIPDataStream() { if (pipConnected) { byte[] msg = NetworkHelper.CreateDatagram(PacketType.PIP_START, null); udpClient.Send(msg, msg.Length, pipAddr); PIPController.instance.pipSending = true; } else { Debug.Log("StartPIP: PIP not connected"); } }
public void DisconnectPIP() { if (pipConnected) { byte[] msg = NetworkHelper.CreateDatagram(PacketType.PIP_DISCONNECT, null); udpClient.Send(msg, msg.Length, pipAddr); pipAddr = null; pipConnected = false; } else { Debug.Log("StartPIP: PIP not connected"); } }
public void DisconnectPip() { byte[] msg = NetworkHelper.CreateDatagram(PacketType.PIP_DISCONNECT, null); udpClient.Send(msg, msg.Length, pipAddr); pipConnected = false; }
public void ReceiveDatagram(IAsyncResult ar) { UdpClient u = ((UdpState)(ar.AsyncState)).u; IPEndPoint e = ((UdpState)(ar.AsyncState)).e; byte[] recv = u.EndReceive(ar, ref e); switch (recv[0]) { case PacketType.CAM_DISCOVERY: if (discoveryingStream) { Debug.Log("Found a streaming client"); Thread.Sleep(1000); tcpClient = new TcpClient(e.Address.ToString(), dataPort); tcpStream = tcpClient.GetStream(); Debug.Log("Connected to streaming client"); camConnected = true; } else { Debug.Log("Got CAM_DISCOVERY whilst not discovering"); } break; case PacketType.PIP_DISCOVERY: if (!pipConnected) { Debug.Log("Pip attempting to connect"); byte[] reply = NetworkHelper.CreateDatagram(PacketType.PIP_DISCOVERY, null); pipAddr = e; udpClient.Send(reply, reply.Length, pipAddr); pipConnected = true; } else { byte[] reply = NetworkHelper.CreateDatagram(PacketType.PIP_REJECT, null); udpClient.Send(reply, reply.Length, e); } break; case PacketType.PIP_DISCONNECT: Debug.Log("Pip disconnected"); pipAddr = null; pipConnected = false; PIPController.instance.pipSending = false; break; case PacketType.PIP_GYRODATA: if (pipAddr.Address.ToString() == e.Address.ToString()) { GetPIPGyroData(recv); } break; default: Debug.Log("Unknown datagram"); break; } // Get next UDP Datagram UdpState s = new UdpState(); s.e = any; s.u = udpClient; udpClient.BeginReceive(new AsyncCallback(ReceiveDatagram), s); }