在设备更新之前,套接字关闭

时间:2016-03-30 22:14:34

标签: c# sockets rfid

我尝试将一些数据发送到RFID阅读器以使用套接字更新其状态。但是,当我尝试正确关闭插座时,状态不适用于阅读器(如哔声或颜色变化)。但是,我很快就从读者那里得到了回声响应。

byte[] bytes = new byte[1024];
//send green status
RFIDStatus status = new RFIDStatus();
status.State = RFIDState.Authenticate;
status.Green = RFIDGreen.On;
status.Red = RFIDRed.Off;
status.BeepLength = BeepSound.TwoShort;

string command = string.Format("R1={0} G1={1} S1={2} \r\n", (int)status.Red, (int)status.Green, (int)status.BeepLength);
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocket.Connect(remoteEP);

clientSocket.Send(Encoding.ASCII.GetBytes(command));
int byteRec = clientSocket.Receive(bytes);

Console.WriteLine("Echoed test = {0}", Encoding.ASCII.GetString(bytes, 0, byteRec));

clientSocket.Shutdown(SocketShutdown.Both);
clientSocket.Close();

如果我不关闭插座,RFID阅读器会正确更新其状态。有没有我可能遗失的东西?将socket.NoDelay设置为false也不能解决此问题。

0 个答案:

没有答案