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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Overview 15<br />

method calls coded by developers, not the actual messages that travel over the<br />

network. In this protocol, the server starts first, and waits for a connection from a<br />

client. The client connects to the server and sends a command: the string T to request<br />

a temperature measurement. The server responds by sending back the temperature,<br />

expressed in a string such as 72.1. Then the client may send another command, or<br />

it may close the connection and exit. If the client closes, the server may wait for<br />

another client to connect, or it may also exit. The server can only accommodate one<br />

client connection at a time.<br />

2.3 Sockets<br />

<strong>We</strong> implement our protocol using sockets, anapplication programming interface<br />

(API) for communicating over TCP/IP networks. The socket API is one of the<br />

fundamental technologies of the Internet and is familiar to many developers. The<br />

.NET framework provides an implementation of this API in the Socket class in the<br />

System.Net.Sockets namespace.<br />

Establishing a connection requires several steps, where each partner calls methods<br />

in the socket API in a particular sequence (Figure 2.2). In the Server, Socket creates<br />

a listener socket, Bind associates it with an IP address and a port number, and Listen<br />

prepares for a connection. Accept makes the connection and creates a connection<br />

socket to use for that connection. In the Client, Socket creates a socket and Connect<br />

makes the connection. Once the connection is made, both partners call Send and<br />

Receive to exchange messages. In our protocol, the client sends first. Both partners<br />

call Close to finish the connection. In our protocol, the client closes first. Finally,<br />

the server calls Close on its listener socket.<br />

2.4 Libraries<br />

Like most applications, our Monitor and Logger programs use libraries. They do<br />

not call the .NET sockets API directly. Instead, they call methods in Client and<br />

Server classes that we wrote (Figures 2.3–2.5). These classes are wrappers for<br />

.NET sockets that provide a similar but simplified API that is specialized for remote<br />

instrument applications. Each wrapper method Socket, Bind, and so on, calls the<br />

.NET socket method with the same name, but uses fewer parameters, or more<br />

convenient parameters. For example, the client’s Receive and the server’s Send<br />

methods handle floating point numbers (the temperature samples) rather than arrays<br />

of bytes, as the .NET socket API does. Although these classes are more specialized<br />

than the .NET Socket class, they still support other applications and protocols<br />

besides the ones described here (Exercise 1).<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!