What "user" do you want to ask? Is it somebody sitting next to the server waiting to approve connections? Do you have to send a message somewhere and receive a response? Is the "user" the client who is trying to connect, and if so what are you going to ask?
I think I might understand the question now. It isn't about asking the "user" at all. I think the question is, how do you listen for a socket connection without using the accept() method.
Why would you want to do that? If you don't call accept() then you don't know anything at all about the connection which is about to be made. So what are you going to do? Ask the "user" if they want to accept this connection about which there is no information at all?
Why not accept the connection, then decide if you want to allow it to proceed? You can always close it whenever you like. Just because the method is named "accept" that doesn't mean you are forced to write code which processes any request that comes over the connection.
When you accept a Socket connect all you get is the Socket. Typically, the client send something to the server and only then does the server decide if what the client requests is allowed. If not, the server can send a response and close the socket.
If you want to restrict which clients can access your server you can install a firewall which can allow clients from limited IP addresses.
Paul i wanna know about the incoming connection so that i will choose between deny or accepting
if i dont know about the connection than how will i be to know if someone is sending me a file.
what peter said is what i want and i could have done it this way
but its much easier to know about the incoming connection cause if the server didnt accept the connection the client will be forced to wait without needing to notify him and tell him to initiate the transfer
No, Peter is correct. You accept the connection and then decide what to do with it. Of course the client will be forced to wait until you accept it, but once you do then you can process the transfer. Or not, if that's what you want to do. I guess I still don't understand the question in the background, though. What is stopping you from doing it the same way that every other server in the world already does it?
Well, I am sorry if you thought that was an insult. I apologize for that.
So you want the short answer? No, the only way to find out about a connection is to accept it. I can't see what your problem is with doing that, though. Just accept it and deal with it. If you want to deny it, then just close the connection.