/// <summary> /// Server listens for incoming skelton data, and sets skeletonReady value to true when recieved. /// </summary> private void Listen() { try { server = new TcpListener(IPAddress.Any, port); server.Start(); Debug.Log("Listening..."); while (true) { this.client = server.AcceptTcpClient(); Debug.Log("Client accepted"); this.stream = client.GetStream(); BinaryFormatter bf = new BinaryFormatter(); while (client.Connected) { this.skeletonSerial = (SSkeleton)bf.Deserialize(stream); Debug.Log("Skeleton is ready!"); skeletonReady = true; } } } catch (SocketException e) { Debug.Log(e); } }
/// <summary> /// Sends the specified SkeletonData over the network as a serializable skeleton (SSkleton) object. /// </summary> /// <param name="skeleton"> The SkeletonData object that must be sent. </param> public void SendSkeletonData(SkeletonData skeleton) { SJoint[] serialJoints = ScanSerializer.SerializeJoints(skeleton.jointPositions, skeleton.jointRotations); SBone[] serialBones = ScanSerializer.SerializeBones(skeleton.bonePositions, skeleton.boneRotations, skeleton.boneScales); SSkeleton serialSkeleton = new SSkeleton(serialJoints, serialBones); Debug.Log("SkSending"); try { stream = client.GetStream(); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(stream, serialSkeleton); stream.Flush(); Debug.Log("SkSent"); } catch (SocketException e) { Debug.Log(e); } }