1

I Listen to specific port with BeginReceive() method.
How I can find sender's IP?

Thank you.

1 Answer 1

3

I think you should elaborate your questions with more details.

Anyway you can find a complete example on how to use BeginReceive() and the other asynchronous methods of the Socket class in a clear and detailed "Asynchronous Server Socket Example" MSDN Sample.

The trick as you will read, is to initialize a custom state object (where you can put the opened Socket information) when you accept the connection and you are going to call BeginReceive, so that the receive callback will be able to retrieve that state with IAsyncResult.AsyncResult property.

Following the linked example, you can retrieve the "sender" (remote) ip address this way (in AcceptCallback, ReadCallback, where handler is an istance of the Socket class):

IPAddress remoteAddress = ((IPEndPoint)handler.RemoteEndPoint).Address;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.