July 2017
Beginner to intermediate
390 pages
10h 53m
English
Now, replace that last comment line with the following:
while (true)
{
var client = _listener.AcceptTcpClient();
Console.WriteLine("We are connected");
var dataStructure = new SomeDataStructure()
{
X = -2.0f,
Y = 0.5f,
Z = -1.5f
};
var dataToSend = JsonConvert.SerializeObject(dataStructure);
using (var writer = new StreamWriter(client.GetStream()))
{
writer.Write(dataToSend);
writer.Flush();
}
client.Close();
}
This is an endless loop. Well, it is endless until somebody presses a key in the main thread that will kill this thread. We call AcceptTcpClient. This is a blocking call that waits until someone actually tries to connect to our server on port 8000. The moment this happens, we create a new instance of our data structure, ...
Read now
Unlock full access