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 17<br />

using System;<br />

using System.Net;<br />

using System.Net.Sockets;<br />

namespace ClientServerImpl<br />

{<br />

// Wrapper for .NET server socket<br />

public class Server<br />

{<br />

Socket listenerSocket; // assigned by Socket<br />

Socket connectionSocket; // assigned by Accept, used by Send etc.<br />

const int BUFLEN = 40;<br />

byte[] receiveBuf = new byte[BUFLEN];<br />

// method Client.Socket assigns instance of System.Net.Sockets.Socket<br />

public void Socket()<br />

{<br />

listenerSocket = new Socket(AddressFamily.InterNetwork,<br />

SocketType.Stream, ProtocolType.Tcp);<br />

}<br />

public void Bind(string ipAddr, int port)<br />

{<br />

listenerSocket.Bind(new IPEndPoint(IPAddress.Parse(ipAddr), port));<br />

}<br />

public void Listen()<br />

{<br />

const int backlog = 0;<br />

listenerSocket.Listen(backlog);<br />

}<br />

// Socket.Accept returns connectionSocket used by Send, Receive, etc.<br />

public void Accept()<br />

{<br />

connectionSocket = listenerSocket.Accept();<br />

}<br />

// to be continued ...<br />

Figure 2.3. Remote instrument server class (1).<br />

<strong>We</strong> will now briefly describe how to build libraries in the .NET framework.<br />

<strong>We</strong> put each class, Client and Server, in its own file, Client.cs and Server.cs,<br />

respectively. This is a common convention but it is not required. This command<br />

invokes the C# compiler csc to compile the client library.<br />

csc /target:library Client.cs<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!