【问题标题】:A simple client-server application一个简单的客户端-服务器应用程序
【发布时间】:2014-08-21 20:41:53
【问题描述】:

我创建了 2 个控制台应用程序:

服务器:

TcpListener myList = new TcpListener(IPAddress.Parse("serverIP"), 8001);
while (true)
{
   myList.Start();
   Socket s = myList.AcceptSocket();
   byte[] b = new byte[100];
   int k = s.Receive(b);
   for (int i = 0; i < k; i++) Console.Write(Convert.ToChar(b[i]));
   s.Send(new ASCIIEncoding().GetBytes("The string was recieved by the server."));
   Console.WriteLine("\nSent Acknowledgement");
   s.Close();
}

客户:

while (true)
{
   TcpClient tcpclnt = new TcpClient();
   tcpclnt.Connect(serverIP, 8001);
   Stream stm = tcpclnt.GetStream();
   byte[] ba = new ASCIIEncoding().GetBytes(Console.ReadLine());
   Console.WriteLine("Transmitting.....");
   stm.Write(ba, 0, ba.Length);
   byte[] bb = new byte[100];
   int k = stm.Read(bb, 0, 100);
   for (int i = 0; i < k; i++) Console.Write(Convert.ToChar(bb[i]));
   tcpclnt.Close();

}

当这两个应用程序在我的机器上运行时它们都可以正常工作,但是当我在 Windows Server 2008 (Windows Azure) 上运行服务器应用程序时出现错误:

连接尝试失败,因为连接方没有 一段时间后正确响应,或建立连接 失败,因为连接的主机没有响应

关于声明:tcpclnt.Connect(serverIP, 8001);

我应该如何配置才能运行我的应用程序?

我应该在这里改变一些东西吗?

`

【问题讨论】:

  • 这听起来很明显,但是您是否检查过服务器的防火墙是否正在断开连接?
  • @chris,请问您可以提供一些详细信息吗?我将防火墙屏幕附加到我的帖子中。请检查。
  • @chris 我为我的应用程序创建了防火墙规则以允许连接。

标签: c# azure client-server windows-server-2008 tcpclient


【解决方案1】:

不要忘记在 Azure 门户中为您的应用程序创建一个“端点”。

在 Azure 门户中导航到您的 VM,然后选择“ENDPOINTS”,使用您希望服务运行的端口创建。

此外,如您的屏幕截图所示,请确保您在 VM 的 Windows 防火墙中打开了该端口。

【讨论】:

  • 我创建了一个端点:协议 - TCP,私有端口 - 8001,公共端口 - 8001。
猜你喜欢
  • 2015-12-25
  • 1970-01-01
  • 1970-01-01
  • 2013-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多