Unity to Node.js UDP: datagrams received are all empty.

Hello,

CODE BELOW

Having some trouble getting this to work, I can send to the server fine, but all messages from the server come back empty. Output from client shows up as null so… it knows a message was received.
No error server side or client side. Just empty buffers ;(

I have also tried the Asyncronous setup (BeginRecieve → EndRecieve). Exact same results, just receiving empty packets.

Does anyone spot anything obviously wrong systemically or otherwise?

Any and all help is appreciated!

Client:

IPEndPoint server;
UdpClient client = new UdpClient ();
UTF8Encoding encoding = new UTF8Encoding ();
Thread networkThread;
string serverIP = "127.0.0.1";
int serverHTTPPort = 9081;
int serverUDPPort = 9082;
bool connected;

void UDPThread () {
		while (true) {
			byte[] buffer = client.Receive (ref server);
			UDPReceive (buffer);
		}
	}

	void UDPReceive(byte[] buffer){
		string message = encoding.GetString (buffer);
		JsonObject json = JsonUtility.FromJson <JsonObject> (message);
		Debug.Log (json);
		receive (message);
	}

	void UDPSend (string target, string action, params string[] values){
		JsonObject requestJson = new JsonObject (target, action, values);
		string requestString = JsonUtility.ToJson (requestJson);
		byte[] request = encoding.GetBytes (requestString);
		//client.Send (request, request.Length, serverIP, serverUDPPort);
		client.Send (request, request.Length);
	}

	public void UDPConnect () {
		networkThread = new Thread (new ThreadStart (UDPThread));
		server = new IPEndPoint (System.Net.IPAddress.Parse (serverIP), serverUDPPort);
		networkThread.IsBackground = true;
		client.Connect (server);
		networkThread.Start ();
	}

	public void UDPDisconnect () {
		networkThread.Abort ();
		client.Close ();
	}

Client Output:

Server:

udpServer.on ('message', function (message, rinfo) {
	controller.NETWORK.receive (message, rinfo, function (result) {
		send (result, rinfo.port, rinfo.address);
	})
});

function send (message, port, address) {
	udpServer.send (message.toString (), message.length, 0, port, address, function (err) {
		if (!err) {
			console.log ('UDP => Sending: ' + message);
		} else {
			console.log (err);
		}
		
	});
}

Server Output:

70683-server-output.png

Well, is the message actually empty of just the deserialized object? It’s possible that the FromJson method failed to create the object from the json data. How is “JsonObject” defined? Is the class derived from another class? Is it marked as Serializable? Does it have a parameterless default constructor? If not the JsonUtility can’t create an instance of the class.