TCP Stream is empty

Hey, i´m trying to setup a TCP communication between a server and a client. I get my client connected to the server, so far so good. Now i´m trying to send a message via stream.write to the server. The server doesnt recognize the message until im disconnecting the client. Then the “readingDone” method gets fired. But even then the message is empty.
I tried to follow this example but i dont understand what they really did other than me. Except of mine is way less complex because i only need a message from the client to the server and not a chat option.

Below my server code:

public class Server : MonoBehaviour
{
	TcpClient client = new TcpClient();
	TcpListener listener;
	int port = 8010;

	byte[] bytes = new byte[500];
	String data = null;

	NetworkStream stream;

	public void Start(){
	
		listener = new TcpListener (IPAddress.Any, port);
		listener.Start ();
		listener.BeginAcceptTcpClient (OnServerConnect, null);
		//StartCoroutine (connecting ());
		
		}


	void OnServerConnect(IAsyncResult ar){


		client = listener.EndAcceptTcpClient (ar);
		Debug.Log ("Connected!!!!");
		listener.BeginAcceptSocket (OnServerConnect, null);

		stream = client.GetStream ();
		stream.BeginRead (bytes, 0, bytes.Length, readingDone, null);
	}
		


	void readingDone(IAsyncResult ar){
		int length = stream.EndRead (ar);
		data = System.Text.Encoding.UTF8.GetString (bytes, 0, length);
		stream.BeginRead (bytes, 0, bytes.Length, readingDone, null);
	
	}

	void Update(){
		if(data != null)
		Debug.Log (data);
	
	
	}

	protected void OnApplicationQuit(){
		listener.Stop ();
		client.Close ();
	
	
	}
		
}

client:

public class Client : MonoBehaviour
{

	TcpClient client = new TcpClient();
	IPAddress serverIp = IPAddress.Parse("127.0.0.1");
	int port = 8010;

	//messagestuff
	String msg = "TestMessage";
	//byte[] data;

	NetworkStream stream;

	public void Start(){
		
		client.BeginConnect (serverIp, port, (ar) => client.EndConnect (ar), null);

		stream = client.GetStream ();


		Send ();

	}

	public void Send(){



		byte[] data = System.Text.Encoding.UTF8.GetBytes (msg);
		stream.Write(data, 0, data.Length);
	
	}

I tried to close the client connection after the writing is done, but it doesnt close. It seems like the writing process does block the rest of the method? Maybe someone can help me on this one, im stuck now for a few days and cant find a proper solution. Thanks!

There are some good networking example about TCP/UDP. You might be interested.

FM Exhibition Tool Pack | Forum

You can stream game view / webcam / audio between multiple platforms in local network.
All written in C# and easy to modify.

Supported Platform: iOS/Android/Mac/PC