聊天程序cllient方面的问题 [英] Problem with Chat program cllient side

查看:143
本文介绍了聊天程序cllient方面的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对套接字编程没有多少经验,但我遇到了客户端软件的问题。如果我在安装服务器软件的同一台计算机上运行客户端,它可以正常工作。这是客户端可以登录服务器没问题,但如果我在客户端尝试登录时在同一网络上的另一台计算机上安装客户端软件,我会收到以下消息:

没有连接可以因为目标机器主动拒绝了它127.0.0.1

在服务器和客户端软件中,我执行以下操作:

IPHostEntry ipHostEntry = Dns.GetHostEntry(localhost );

有人知道我做错了吗?

谢谢Mike

解决方案

使用localhost 你已将其硬编码为仅与同一主机上的客户端和服务器一起使用。

您需要某种方式让用户向客户端指定服务器的主机名,然后在与服务器的连接中使用该主机名。

你可能需要这样的东西:

  //  建立套接字的远程端点。 
// $的名称b $ b // 远程设备是host.contoso.com。
IPHostEntry ipHostInfo = Dns.Resolve( host.contoso.com);
IPAddress ipAddress = ipHostInfo.AddressList [ 0 ];
IPEndPoint remoteEP = new IPEndPoint(ipAddress,port);来自 MSDN:异步客户端的

套接字示例 [ ^ ]


I don't have much experience with socket programming but I running into problems with the software on the client side. If I run the client on the same computer as where the server software is installed it works fine. That is the client can log in with the server no problem but if I install the client software on another computer on the same network when the client attempts to log in I get the following message:
no connection could be made because the target machine actively refused it 127.0.0.1
In both the server and client software I do the following:
IPHostEntry ipHostEntry = Dns.GetHostEntry("localhost");
Does someone know what I am doing wrong?
Thanks Mike

解决方案

By using "localhost" you've hardcoded it to only work with the client and server on the same host.
You'll need some way for the user to specify to the Client the hostname for the Server an then use that in the connection to the server.
You probably need something like this:

// Establish the remote endpoint for the socket.
// The name of the
// remote device is "host.contoso.com".
IPHostEntry ipHostInfo = Dns.Resolve("host.contoso.com");
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);

from MSDN: Asynchronous Client Socket Example[^]


这篇关于聊天程序cllient方面的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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