【发布时间】: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