aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Socket Programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Socket Programming" Watch "Socket Programming" New topic
Author

Socket Programming

Oduabuna Francis
Greenhorn

Joined: Jun 21, 2013
Posts: 2

Hi.
Is there a way in which a I can program a server to be the one to pickup requests from a client (whose IP address and port is stated) instead of the client forwarding the requests to it. I know for normal sockets I would have to create a server as follows:

What if I want the server to be the one to pick a request from a client of IP address x.x.x.x on port 8081, what should I do?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Oduabuna Francis wrote:Hi.
Is there a way in which a I can program a server to be the one to pickup requests from a client (whose IP address and port is stated) instead of the client forwarding the requests to it. I know for normal sockets I would have to create a server as follows:

What if I want the server to be the one to pick a request from a client of IP address x.x.x.x on port 8081, what should I do?



Not sure what you mean by "pick a request from a client of IP address x.x.x.x on port 8081"? Are you asking to see if it can only accept from certain addresses and port? If so, then no -- not really... but ... after accepting, I guess you can check the remote address and port, and close the socket if it is not within the range that you want. Does that work?

If this is not what you mean, then please elaborate.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 133

Oduabuna Francis wrote:Hi.
Is there a way in which a I can program a server to be the one to pickup requests from a client (whose IP address and port is stated) instead of the client forwarding the requests to it. I know for normal sockets I would have to create a server as follows:

What if I want the server to be the one to pick a request from a client of IP address x.x.x.x on port 8081, what should I do?


If you need accept all Sockets(Clients) you need to use Thread.

If you need to accept specific client use


You should be able to handle Exceptions
Hope this helps,
Supun


Are you better than me? Then please show me my mistakes..
Oduabuna Francis
Greenhorn

Joined: Jun 21, 2013
Posts: 2

Thanks Supun Lakshan. I wanted to ensure it only accept from certain addresses and port. I used what you suggested and it did help. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket Programming