0
問題: 服務器應向客戶端發送SerialPort命令(例如「S」)並接收端口。發送另一個命令(例如「r01」)。向客戶端發送消息並接收對接收到的答案的答案+行爲
示例:服務器發送「S」並從客戶端收到「N」,以便服務器發送另一個「S」。如果收到!=「N」,則發送「r01」等。
我可以發送消息給客戶,但我無法收到答案並將其存儲/使用。
我試過至今:
)保存接收到的信息轉化爲serv.connectedClients [ID] .receive
服務器: 工人階級:
public void doSomething(Service serv, string ID)
{
serv.SendMessageToClient(client_name, "S"); //send first message
data = serv.connectedClients[ID].receive.ToString(); //the .receive is empty but should have the clients answer stored
if(data != ""){
serv.SendMessageToClient(client_name, "r01"); //send second message
serv.connectedClients[ID].Information = serv.connectedClients[ID].receive.ToString();
}
}
在服務.cs:
public void getPortMsg(string msg)
{
connectedClients[OperationContext.Current.Channel.SessionId].receive = msg;
}
在客戶端:
void callback_OnMessageReceivedEvent(string message)
{
string portmsg = "";
portmsg = rfid.send(message); //portmsg gets the port.readline info
client.getPortMsg(portmsg); //send portmsg to server
}
而且rfid.send:
public string send(string senden)
{
string data = "";
port.WriteLine(senden);
data = port.ReadLine();
return data;
}
順序:服務器將消息發送給客戶端。客戶端收到該消息並調用其中包含答案的服務方法。服務器應該使用這個答案,但是在他得到答案之前發送下一條消息。
希望有人知道答案。