Created
&& serverSocket == Socket.Listening);
}
[Action]
public static void ClientConnect()
{
clientSocket = Socket.Connecting;
}
public static bool ClientSendEnabled()
{
return (clientSocket == Socket.Connected
&& phase == Phase.Send);
}
// No parameter needed here, client always sends the same thing
[Action]
public static void ClientSend()
{
phase = Phase.ServerReceive;
}
// continued ....
Figure 5.10. Remote instrument client/server: model program (part 4).
80 Model Programs
// ... continued
public static bool ClientReceiveEnabled()
{
return (clientSocket == Socket.Connected
&& phase == Phase.ClientReceive);
}
// Return value needed here, server sends different values
[Action]
public static double ClientReceive()
{
double t = clientBuffer;
clientBuffer = EmptyBuffer;
phase = Phase.Send;
return t;
}
public static bool ClientCloseEnabled()
{
return (clientSocket == Socket.Created
|| clientSocket == Socket.Connected);
}
[Action] public static void ClientClose()
{
clientSocket = Socket.Closed;
}
}
}
Figure 5.11. Remote instrument client/server: model program (part 5).
all the action method names must be different (you cannot use the class names to
distinguish them).
The Socket type enumerates the values of the two control state variables server-
Socket and clientSocket. They represent the steps in the protocol shown in Chapter
2, Figure 2.
Pages:
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127