为什么服务器和客户端无法使用套接字编程c#进行通信? [英] Why Server and Clients not communicating using socket programing c#?

查看:64
本文介绍了为什么服务器和客户端无法使用套接字编程c#进行通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#套接字编程制作样本c#控制台应用程序,用于客户端和服务器之间的通信。



通信意味着:(在我的程序中,字符串hello world是通过客户端和服务器接收和响应发送回服务器。)



客户端和服务器可以在同一网络上相互通信,只是IP不同。



但是如果客户在其他网络/不同的网络上,客户端不会将字符串发送到服务器。

例如和现在一样认为你和我在不同的网络上。我制作我的电脑服务器,你制作你的电脑客户端。运行我的示例{client.cs} exe,在client.cs中有我的服务器IP包括如下:



string serverDNS =xxx.xx.xx.xx ; //这里我把服务器IP。 。

int port = 0;

System.Int32.TryParse(11000,out port);



try

{

IPAddress [] addrs = System.Net.Dns.GetHostAddresses(serverDNS);

foreach(IP地址addr in addrs)如果(addr.AddressFamily == AddressFamily.InterNetwork)

{

endpoint = new IPEndPoint (addr,port);

休息;

}

}

}



我还在我的服务器上运行我的样本。在这种情况下,我将无法从您那里收到字符串hello worlds(客户端电脑)>>>这是一个问题..

任何人都可以帮我吗???



如果在你心中因为FireWall问题,然后告诉我如何追踪防火墙问题?并告诉我它的客户防火墙问题或服务器防火墙......还告诉我如何解决这个问题?

如果由于路由器那么还有其他解决方案可以修复,而无需设置路由器等?



谢谢..

i make sample c# Console application for communication between clients and server using c# socket programming.

communication mean : (in my program the string "hello world" is send by client and server receive and response back to server .)

Clients and Server can communicate with each other when both on same network ,just IP different.

but Clients not sending the string to the server if clients are on other network /Different Network .
e.g think same as now you and me are on different network. i make my pc server and you make your pc client. run my sample {client.cs} exe ,in client.cs there is My server IP include like below:

string serverDNS = "xxx.xx.xx.xx"; // here i put server IP. .
int port = 0;
System.Int32.TryParse("11000", out port);

try
{
IPAddress[] addrs = System.Net.Dns.GetHostAddresses(serverDNS);
foreach (IPAddress addr in addrs)
{
if (addr.AddressFamily == AddressFamily.InterNetwork)
{
endpoint = new IPEndPoint(addr, port);
break;
}
}
}

and i also run on my server pc my sample. in that case i will not able to receive a string "hello worlds" from you (Client pc)>>> this is a problem..
can any body help me please ???

And if in you mind its because of FireWall issue, then tell how can i trace firewall issue ? and also tell me its Clients FireWall issue or Server firewall..and also tell me how to resolve this??
and if due to router then is there any other solution for fix,,without setting router etc ??

Thanks you ..

推荐答案

参见如果客户端和服务器在不同的网络上,那么他们可以使用套接字编程相互通信? [ ^ ]。


这篇关于为什么服务器和客户端无法使用套接字编程c#进行通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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