B
B
bagyr2011-12-14 12:58:48
C++ / C#
bagyr, 2011-12-14 12:58:48

System.Net.Sockets.TcpClient find out client ip address?

Highly simplified code:

TcpListener listener = new TcpListener(IPAddress.Any, 30000);
listener.Start();
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine(client.Client.RemoteEndPoint);
listener.Stop();
Console.ReadLine();

Stably returns 0.0.0.0:0, with AcceptSocket the situation is the same, while the bytes run, everything else works.
A very roughly equivalent Python code works fine:
import SocketServer

class MyTCPHandler(SocketServer.BaseRequestHandler):

    def handle(self):
        print self.client_address[0]

if __name__ == "__main__":
    HOST, PORT = "0.0.0.0", 30000
    server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
    server.serve_forever()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question