问题描述
我最近开始创建聊天服务器,并为我的朋友和客户端程序创建客户端程序,以便在服务器程序可以在计算机上运行的地方使用它,并且当我使用该客户端程序时,我会将客户端程序提供给我的朋友进行聊天等.
I have recently started creating chat server, and client programs for my friends and I to use where the server program would be run on my computer, and I would give the client program to my friends to chat etc. when I use the
SockAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
if(connect(sConnect,(SOCKADDR*)(&SockAddr),sizeof(SockAddr))!=0);
代码部分,它可以很好地在我的计算机上工作,可以连接,并且一切都可以正常工作,但是如果我将127.0.0.1更改为我的真实IP(例如,假设其11.11.11.11),则客户端程序将无法连接. (显然,我这样做是为了使客户端程序不会尝试连接到我的朋友计算机上将要运行的端口,但是它将连接到我的端口之一)
任何帮助将不胜感激
Brett
section of code it works perfect on my computer, I can connect, and everything works perfectly, but if I change the 127.0.0.1 to my real ip (just for example lets say that its 11.11.11.11) the client program wont connect. (obviously i do this so that the client program wont try to connect to a port on my friends computer where it will be run, but it will connect to one of the ports on mine)
any help would be appreciated
Brett
推荐答案
这篇关于Winsock连接麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!