• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Socket Programming

 
Greenhorn
Posts: 2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic