.net套接字不捕获tcp数据包

时间:2013-04-03 15:39:58

标签: .net sockets tcp stream

我有一台设备向我的计算机发送了一些tcp数据包。我可以用嗅探器看到这个数据包。

但是,使用.Net套接字时,此设备没有连接。

嗅探器将此数据包显示为TCP数据包。

如何在没有连接的情况下收到此TCP数据包?

我应该使用Raw套接字吗?但似乎Raw套接字无法发送TCP数据包。

可能是一个标识为TCP数据包的自定义数据包吗?

我使用此example中的代码。

public static void StartListening() {
    // Data buffer for incoming data.
    byte[] bytes = new Byte[1024];

    // Establish the local endpoint for the socket.
    // The DNS name of the computer
    // running the listener is "host.contoso.com".
    IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
    IPAddress ipAddress = ipHostInfo.AddressList[0];
    IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);

    // Create a TCP/IP socket.
    Socket listener = new Socket(AddressFamily.InterNetwork,
        SocketType.Stream, ProtocolType.Tcp );

    // Bind the socket to the local endpoint and listen for incoming connections.
    try {
        listener.Bind(localEndPoint);
        listener.Listen(100);

        while (true) {
            // Set the event to nonsignaled state.
            allDone.Reset();

            // Start an asynchronous socket to listen for connections.
            Console.WriteLine("Waiting for a connection...");
            listener.BeginAccept( 
                new AsyncCallback(AcceptCallback),
                listener );

            // Wait until a connection is made before continuing.
            allDone.WaitOne();
        }

    } catch (Exception e) {
        Console.WriteLine(e.ToString());
    }

    Console.WriteLine("\nPress ENTER to continue...");
    Console.Read();

}

它适用于很多客户端套接字

谢谢,抱歉我的英语不好。

0 个答案:

没有答案
相关问题