• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket Programming

 
Oduabuna Francis
Greenhorn
Posts: 2
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21227
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Supun Lakshan Dissanayake
Ranch Hand
Posts: 135
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Oduabuna Francis
Greenhorn
Posts: 2
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic