WM6 的 C# TCP 客户端

发布于 2024-09-08 17:41:57 字数 915 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自找没趣 2024-09-15 17:41:57

我想我发现了问题。当我的 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!

剪不断理还乱 2024-09-15 17:41:57

检查您的防火墙,并确保您的服务器正在运行。

我不知道为什么你看不到错误消息;尝试将其转换为 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 the ErrorCode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文