- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
可能只看这个视频:http://screencast.com/t/OWE1OWVkO如您所见,连接启动(通过 telnet 或 firefox)与我的程序第一次收到消息之间的延迟。
这是等待连接的代码
public IDLServer(System.Net.IPAddress addr,int port)
{
Listener = new TcpListener(addr, port);
Listener.Server.NoDelay = true;//I added this just for testing, it has no impact
Listener.Start();
ConnectionThread = new Thread(ConnectionListener);
ConnectionThread.Start();
}
private void ConnectionListener()
{
while (Running)
{
while (Listener.Pending() == false) { System.Threading.Thread.Sleep(1); }//this is the part with the lag
Console.WriteLine("Client available");//from this point on everything runs perfectly fast
TcpClient cl = Listener.AcceptTcpClient();
Thread proct = new Thread(new ParameterizedThreadStart(InstanceHandler));
proct.Start(cl);
}
}
(我在将代码放入代码块时遇到了一些问题)
我已经尝试了几种不同的方法,可能是我使用的是 TcpClient/Listener 而不是原始 Socket 对象吗?我知道这不是强制性的 TCP 开销,我已经尝试在同一个线程中运行所有内容,等等。
最佳答案
也许是某种 dns 解析?您是使用 IP 地址来访问您的服务器的主机还是由您的 DNS 解析的某个名称? ParmesanCodice 提供的代码应该可以立即运行,除非客户端/网络端出现问题。
尝试将以下行添加到您的 windows\system32\drivers\etc\hosts:
127.0.0.1 localhost
它可能会解决您的问题或仅连接为 127.0.0.1:85
关于c# - ~1 秒 TcpListener Pending()/AcceptTcpClient() 滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2740664/
我正在使用使用 TcpListener 的 C++/CLI 制作一个小程序,我知道 AcceptTcpClient 是一种同步方法,它会阻塞 UI 线程。我如何调用此方法才能使其不会阻塞我的 UI?这
在我的应用程序中,我目前在 AcceptTcpClient(或 EndAcceptTcpClient)抛出异常时停止监听。当我停止监听器(套接字错误 10004)或断开网络适配器时,通常会抛出异常。
我有一个 TcpListener 对象,它在防火墙后面的 4000 端口上运行。显然,为了让外部客户端连接到 TcpListener,需要在防火墙中打开端口 4000;否则,外部连接请求将无法通过。
众所周知,在 C# 中接受传入 TCP 连接的最简单方法是循环 TcpListener.AcceptTcpClient()。此外,这种方式将阻止代码执行,直到获得连接。这对 GUI 有极大的限制,所以
AcceptTcpClient() 阻止应用程序在我调用 thrd.Abort() 后退出。 监听时如何退出应用? 最佳答案 您应该能够通过关闭 TcpListener 来中断对 AcceptTcpC
我想写一个简单的多线程服务器-客户端应用程序我在创建 tcplistenr 时偶然发现了这两个 public void serverListenr { int MessageLengt
我需要一个类来包含 TcpClient 的所有内容 + 几个额外的字段,所以我创建了一个基于 TcpClient 的类: public class MyClient: TcpClient {
据我了解,这些行: var client = await listener.AcceptTcpClientAsync(); var client = listener.AcceptTcpClient(
我必须在Windows窗体的标签上显示客户端ip地址 这是我写的代码 private void Form1_Load(object sender, EventArgs e) {
我正在使用 Powershell 编写一个简单的 TCP/IP 服务器。我注意到 Ctrl-C 不能中断 AcceptTcpClient() 调用。 Ctrl-C 在通话后工作正常。我四处搜索,到目前
可能只看这个视频:http://screencast.com/t/OWE1OWVkO如您所见,连接启动(通过 telnet 或 firefox)与我的程序第一次收到消息之间的延迟。 这是等待连接的代码
我有一个用 Java 实现的套接字监听器应用程序,并且工作正常 C#代码: IPAddress serverAddress = IPAddress.Parse("127.0.0.1")
我是一名优秀的程序员,十分优秀!