当在C#中收到某个字符时如何运行代码
因此,我有AC#程序,当服务器从服务器收到某个字符时,我试图在客户端中运行某个代码。应该发生的事情,如果服务器将G发送到客户端,则应该运行某些代码,然后客户端和服务器确实连接,并且他们确实确认G已发送并接收了G,但IF中的代码不运行。这是客户端代码,在接收G时,应该在客户端上运行代码: 字节[] bb = new Byte [100];
int k = stm.Read(bb, 0, 100);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToString(bb));
string atk = Encoding.ASCII.GetString(bb);
MessageBox.Show("Recieved Command " + atk);
if (atk == "g")
{
MessageBox.Show("information received.);
search.RunWorkerAsync();
}
从服务器收到G,无问题,但代码不运行。我想知道为什么这可能是?谢谢。
so I have a c# program in which I am trying to run a certain code in a client when a certain character is recieved from the server. What is supposed to happen, If the server sends g to the client it's supposed to run certain code, and while then client and server do connect and they do acknowledge g was sent and received, the code in the if then statement does not run. Here is the client code where when receiving g it is supposed to run code on the client:
byte[] bb = new byte[100];
int k = stm.Read(bb, 0, 100);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToString(bb));
string atk = Encoding.ASCII.GetString(bb);
MessageBox.Show("Recieved Command " + atk);
if (atk == "g")
{
MessageBox.Show("information received.);
search.RunWorkerAsync();
}
The g is recieved from the server no problem, but the code does not run. I am wondering why this might be? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将消息框更改为
debug.writeline
还是console.writeline
并显示输出。因此,您提供了完整的回调,因为缺少某些代码
,但是
如果您知道 ascii中的字母“ g”:是“ 103 <)。 /strong>“ hex: 67
直接进行比较而不将其转换为字符串
can you change the message box to
Debug.WriteLine
orConsole.WriteLine
and show the output please.All so your provide your full Callback as some code is missing
But maybe don't convert
if you know the letter "g" in ASCII: is "103" in HEX: 67
do a direct compare without convert it to string