I spent my whole weekend learning how to work with networking programming. It was my very first network programming. Yes, Unity communicate with PD through TCP network. However, it wasn't my code. It was some open-source library I found on internet: KalimbaPD. And it doesn't satisfy our usage. We need to know where PD is at to sync the audio to the track. In short, we need a way for PD to communicate with Unity. So, with Cody's help I created a new network channel for Unity to receive message from PD.
I spend my Saturday night understanding and creating the TCP network so that Unity can listen to PD. Then on Sunday night, I finish 'decipher'ing the data send by Pure Data.
Yes, it is 'decipher' not decipher. Why? Because no decipher is really needed. After I get the data (in bytes), I copied it into character array using Buffer.BlockCopy and... it gave me random Chinese character. Then, I copied it into integer array and... it gave me random number. None of them give me the exact number that I send from PD. So? It is time to try it outside Unity - still using C#! This way I could go step by step debugging it.
I created an empty project with the very exact code I wrote in Unity for the networking. Then I operated PD manually - not through the code like I did in Vinyl. First, I was assured that the send command to the [netsend] did what it supposed to do. Then, instead of sending the data that we needed, I sent only one number and checked what the bytes received. And... the bytes received from PD was exactly the data PD sent. It was send in ASCII. That means what I need to do just Encoding.ASCII.GetString! Now with it finished, I committed my code to our code server.
However, the next day when Mikeh pulled it out to test the latest update, it was broken. It got me really crazy because I did committed those code in the previous day. When I got home, I found that by unknown reason, I had two exact same classes in different folder and by unknown reason, too, Unity let me did it! Strangely enough, it even run with the correct code! Stupid Unity!
I created an empty project with the very exact code I wrote in Unity for the networking. Then I operated PD manually - not through the code like I did in Vinyl. First, I was assured that the send command to the [netsend] did what it supposed to do. Then, instead of sending the data that we needed, I sent only one number and checked what the bytes received. And... the bytes received from PD was exactly the data PD sent. It was send in ASCII. That means what I need to do just Encoding.ASCII.GetString! Now with it finished, I committed my code to our code server.
However, the next day when Mikeh pulled it out to test the latest update, it was broken. It got me really crazy because I did committed those code in the previous day. When I got home, I found that by unknown reason, I had two exact same classes in different folder and by unknown reason, too, Unity let me did it! Strangely enough, it even run with the correct code! Stupid Unity!
No comments:
Post a Comment