Usually, the source program for a library comprises
several classes or other types in several files. Compiling a source program creates
a binary file called an assembly. Assemblies are the software components of the
.NET framework. A library is an assembly intended for use by applications (or
other libraries); it has no main method. A library has the file type dll.
We create another library for the server class. We create a third library for the
temperature sensor class, Temperature (Figure 2.6). This class provides a Sample
method that acquires one sample from the temperature sensor, and a ConvertToCelsius
method that converts a temperature sample from Fahrenheit to Celsius. This
version of Temperature is a simulator; it provides a stub Sample method that does
not require actual sensor hardware, so you can use it on any computer that provides
the .NET framework.
Overview 19
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading; // Thread.Sleep
namespace ClientServerImpl
{
// Wrapper for .NET client socket
public class Client
{
Socket socket;
const int BUFLEN = 4;
byte[] receiveBuf = new byte[BUFLEN];
// method Client.Socket assigns instance of System.Net.Sockets.Socket
public void Socket()
{
socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
}
public void Connect(string ipAddr, int port)
{
socket.
Pages:
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50