套接字异常 [英] Socket exception

查看:142
本文介绍了套接字异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个桌面应用程序正在侦听即将到来的连接请求,这很好.移动方面的东西不能正常工作,我正在尝试通过蓝牙将字符串发送到列表服务器,但是却收到套接字异常:

移动/客户端(Windows Mobile 5.0设备)上的代码:

I have a desktop application listening for in coming connection request, this works fine. What isn''t working fine is the mobile side of things, I am trying to send a string over bluetooth to the listning server but am getting a socket exception:

Code on mobile/client (Windows Mobile 5.0 device):

private void btnPlay_Click(object sender, EventArgs e)
{
    TcpClient tcpClient = new TcpClient(Dns.GetHostName(), 2112); <<ERROR HERE?
    NetworkStream ns = tcpClient.GetStream();
    string objSent = "Play";
    
    int data = Encoding.ASCII.GetByteCount(objSent);
    while (data != -1)
    {
        ns.WriteByte((byte)data);
        data = Encoding.ASCII.GetByteCount(objSent);
    }
    ns.Close();
    tcpClient.Close();
}



错误如下:

错误消息可用于此异常,但无法显示,因为这些消息是可选消息,并且当前未安装在此设备上.对于Windows Mobile 5.0及更高版本,请安装"NETCFv35.Messages.EN.wb.cab",对于其他平台,请安装"NETCFv35.Messages.EN.cab".重新启动应用程序以查看该消息.



Following is the error:

An error message is available for this exception but cannot be displayed because these messages are optional and are not currently installed on this device. Please install "NETCFv35.Messages.EN.wm.cab" for Windows Mobile 5.0 and above or "NETCFv35.Messages.EN.cab" for other platforms. Restart the application to see the message.

推荐答案

Dns.GetHostName()将返回客户端的主机名,而不是服务器的主机名.
新的TcpClient()将需要服务器的名称而不是客户端的名称.
如果您不在同一台计算机上执行此操作,则可能是问题所在.

这是一个疯狂的猜测,因为您没有提供有关异常的任何信息
Dns.GetHostName() returns you the hostname of the client not the server.
new TcpClient() will need the name of the server not the client.
If you are not doing this on the same machine, then this might be the problem.

And this is a wild guess since you have not supplied any information about the exception


很抱歉,以下消息是这样的:

错误消息可用于此异常,但无法显示,因为这些消息是可选消息,并且当前未安装在此设备上.对于Windows Mobile 5.0及更高版本,请安装"NETCFv35.Messages.EN.wb.cab",对于其他平台,请安装"NETCFv35.Messages.EN.cab".重新启动应用程序以查看消息.
Sorry about that, here is the message:

An error message is available for this exception but cannot be displayed because these messages are optional and are not currently installed on this device. Please install ‘NETCFv35.Messages.EN.wm.cab’ for Windows Mobile 5.0 and above or ‘NETCFv35.Messages.EN.cab’ for other platforms. Restart the application to see the message.


这篇关于套接字异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆