27.07.2013 Views

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Overview 21<br />

using System;<br />

using System.Net; // Dns and IPHostEntry<br />

namespace ClientServerImpl<br />

{<br />

// Remote instrument standalone server program, works with Logger client<br />

}<br />

class Monitor<br />

{<br />

#region usage method, writes help text (code not shown)<br />

}<br />

static void Main(string[] args)<br />

{<br />

string host = "127.0.0.1";<br />

int port = 8000;<br />

int nsessions = Int32.MaxValue; // unlimited, in effect<br />

}<br />

IPHostEntry iphe; // for checking host address string<br />

string command;<br />

double temperature;<br />

#region Check and process command line arguments (code not shown)<br />

Server server = new Server();<br />

Temperature sensor = new Temperature();<br />

server.Socket();<br />

server.Bind(host,port);<br />

Console.WriteLine("{0:u} Temperature server at {1} binds port {2}",<br />

DateTime.Now, host, port);<br />

server.Listen();<br />

for (int i = 0; i < nsessions; i++)<br />

{<br />

server.Accept();<br />

Console.WriteLine("{0:u} Temperature server accepts connection",<br />

DateTime.Now);<br />

do<br />

{<br />

command = server.Receive();<br />

if (command.Length > 0) { // command contents don’t matter<br />

temperature = sensor.Sample();<br />

server.Send(temperature);<br />

}<br />

}<br />

while (command.Length > 0); // 0 indicates connection closed<br />

server.CloseConnection();<br />

Console.WriteLine("{0:u} Temperature server connection closed",<br />

DateTime.Now);<br />

}<br />

server.Close();<br />

Console.WriteLine("{0:u} Temperature server exits", DateTime.Now);<br />

Figure 2.7. Temperature monitor, a server application.<br />

more free ebooks download links at:<br />

http://www.ebook-x.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!