MaxValue; // unlimited, in effect
IPHostEntry iphe; // for checking host address string
string command;
double temperature;
#region Check and process command line arguments (code not shown)
Server server = new Server();
Temperature sensor = new Temperature();
server.Socket();
server.Bind(host,port);
Console.WriteLine("{0:u} Temperature server at {1} binds port {2}",
DateTime.Now, host, port);
server.Listen();
for (int i = 0; i < nsessions; i++)
{
server.Accept();
Console.WriteLine("{0:u} Temperature server accepts connection",
DateTime.Now);
do
{
command = server.Receive();
if (command.Length > 0) { // command contents don??™t matter
temperature = sensor.Sample();
server.Send(temperature);
}
}
while (command.Length > 0); // 0 indicates connection closed
server.CloseConnection();
Console.WriteLine("{0:u} Temperature server connection closed",
DateTime.Now);
}
server.Close();
Console.WriteLine("{0:u} Temperature server exits", DateTime.Now);
}
}
}
Figure 2.7. Temperature monitor, a server application.
22 Why We Need Model-Based Testing
using System;
using System.Net; // Dns and IPHostEntry
namespace ClientServerImpl
{
// Remote instrument standalone client program, works with Monitor server.
class Logger
{
#region usage method, writes help text (code not shown)
static void Main(string[] args)
{
string host = "127.0.0.1";
int port = 8000;
int nsamples = Int32.
Pages:
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53