Results 1 to 14 of 14
  1. #1
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Question events on a server socket

    Hello all,

    Is there an way I can look for events on a server socket when there is a client connect request before the server accept it?

    any help is appreciated

    thanks & regards

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by newbiejava View Post
    Is there an way I can look for events on a server socket when there is a client connect request before the server accept it?
    Nope, when a ServerSocket isn't in an accepting state it simply doesn't 'listen' for connection requests. There is a queue for clients waiting for a connection (see the backLog parameter for the constructor) but that's all, there is no event such as 'client waiting to be connected'.

    kind regards,

    Jos

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by newbiejava View Post
    Hello all,

    Is there an way I can look for events on a server socket when there is a client connect request before the server accept it?

    any help is appreciated

    thanks & regards
    Accepting state is the communication initiate point.

  4. #4
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    is there an event handler for a socket which will listen for the connection status?

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    What do you want to use this for?
    What would you do if there was a client connect coming to a ServerSocket?

  6. #6
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    Q: What do you want to use this for?
    A: monitoring multiple client connection

    Q:What would you do if there was a client connect coming to a ServerSocket?
    A: to check max. concurrent client connection..

    any event-driven can I use to monitor it? or do you have any idea?

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    What ever you want to do, you've to accept the client connection. Then before put into your connection pool, validate accordingly you want. Based on the validation you can response to the client.

  8. #8
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    what do you mean by connection pool?
    is that something like connection id that I can use to do something to the connection? .. could you please give me a simple example?

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by newbiejava View Post
    Q: What do you want to use this for?
    A: monitoring multiple client connection

    Q:What would you do if there was a client connect coming to a ServerSocket?
    A: to check max. concurrent client connection..

    any event-driven can I use to monitor it? or do you have any idea?
    Why not extend (or encapsulate) the ServerSocket class in your own class? It can poop up its functionality by adding a PropertyChangeSupport class to it so you can notify any listener when you have accepted a new connection. The API documentation for those classes is your friend.

    kind regards,

    Jos

  10. #10
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    extend (or encapsulate) the ServerSocket class in my own class?
    as a newbie I am more confusing with this :confused:
    could you please give me a simple example for this? .. (just for a clue :))

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by newbiejava View Post
    extend (or encapsulate) the ServerSocket class in my own class?
    as a newbie I am more confusing with this :confused:
    could you please give me a simple example for this? .. (just for a clue :))
    Not 'your class', write another class for that purpose that can accept a client socket (just like a ServerSocket does) but it also can notify any listener for that fact. A ServerSocket can be a (private) member of that class and a PropertyChangeListener can handle the event propagation. Reading the API documentation can do wonders; there will be no need to write much code for it.

    kind regards,

    Jos

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by newbiejava View Post
    what do you mean by connection pool?
    is that something like connection id that I can use to do something to the connection? .. could you please give me a simple example?
    Okay, say you've receive some requests, and if you accept them where you keep those details. May be you've assign an ID. You've to keep all those details in an array, list, etc... General it's call connection pool, more generic word than technical.

  13. #13
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    Thanks for the clue!

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. design & generics for socket server
    By gilme in forum New To Java
    Replies: 1
    Last Post: 06-18-2010, 04:24 AM
  2. typed events vs untyped events.
    By Drun in forum SWT / JFace
    Replies: 0
    Last Post: 11-23-2009, 12:22 PM
  3. Server Socket
    By Moncleared in forum New To Java
    Replies: 1
    Last Post: 09-05-2009, 06:08 AM
  4. (Server)Socket application deploying
    By mdinant in forum Networking
    Replies: 0
    Last Post: 04-09-2008, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •