WM6 的 C# TCP 客户端
我正在尝试使用 Windows Mobile 6 Professional 为 PDA 制作 TCP 客户端应用程序。 我尝试先在我的笔记本电脑上制作它并且成功了。 “智能设备”的代码完全相同,但不起作用。
这是代码:
// IP and Port
string IP = "192.168.1.68";
int port = 1000;
// TCP connection
TcpClient connection;
StreamReader TCPreader;
StreamWriter TCPwriter;
//(...)
try
{
connection = new TcpClient(IP, port);
NetworkStream stream = connection.GetStream();
TCPreader = new StreamReader(stream);
TCPwriter = new StreamWriter(stream);
// wait for welcome message
status_label.Text = TCPreader.ReadLine();
}
catch(Exception ex)
{
MessageBox.Show("ERROR: " + ex.Message);
}
“readLine()”方法调用引发异常。我无法收到该消息,否则我会收到类似“此异常消息未安装,您必须安装 NETCFv35.messages.en.cab”的信息。我已经安装了该 .cab,但收到了相同的消息。
出了什么问题?为什么此代码可以在我的笔记本电脑(WinForms app/NET3.5)上运行,但不能在 PDA(智能设备/NETCF3.5)上运行?有什么建议吗?
提前致谢!
Im trying to make a TCP client application for a PDA with Windows Mobile 6 Professional.
I tried to make it first on my laptop and it worked. The code for the "smart device" is exaclty the same but it doesn't work.
Here it is the code:
// IP and Port
string IP = "192.168.1.68";
int port = 1000;
// TCP connection
TcpClient connection;
StreamReader TCPreader;
StreamWriter TCPwriter;
//(...)
try
{
connection = new TcpClient(IP, port);
NetworkStream stream = connection.GetStream();
TCPreader = new StreamReader(stream);
TCPwriter = new StreamWriter(stream);
// wait for welcome message
status_label.Text = TCPreader.ReadLine();
}
catch(Exception ex)
{
MessageBox.Show("ERROR: " + ex.Message);
}
An exception is thrown on "readLine()" method call. I can't get the message, otherwise I get something like this "this exception message is not installed, you have to install NETCFv35.messages.en.cab". I already installed that .cab but I get the same message.
What is going wrong? Why this code works on my laptop (WinForms app/NET3.5) and doesn't on PDA (Smart Device/NETCF3.5)? Any suggestion?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我发现了问题。当我的 PDA 通过 USB 连接到笔记本电脑时,WiFi 被禁用。 Arghhh 我刚刚断开 PDA 与笔记本电脑的连接,现在我无法从 192.168.1.68 发送/接收消息。
感谢大家的提示!
I think I found the problem. While my PDA is connected through USB to my laptop, WiFi is disabled. Arghhh I just disconnect PDA from my laptop and now I cant send/receive messagens from 192.168.1.68.
Thanks all for your hints!
检查您的防火墙,并确保您的服务器正在运行。
我不知道为什么你看不到错误消息;尝试将其转换为
SocketException
并提取ErrorCode
。Check your firewall, and that your server is running.
I'm not sure why you can't see the error messages; try casting it to
SocketException
and extracting theErrorCode
.