Results 1 to 4 of 4

Thread: Client/Server App

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    11

    Red face Client/Server App

    Hii al;
    i am developping a Client/Server Application and everything is allright, but I have a qu,
    in the server code i am using an open loop ( while (true ) ) to collect the new requests to connect to the server where the accept function is called.
    is not there any way to prevent using this loop? like in VC++ there is an onAccept Event
    i am using netbeans 5.0 and the server is GUI.
    thanks in advance.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Client/Server App

    No such thing. Mostly because there is no central message system: the AWT event dispatching is only for AWT events.

    MFC (which I assume you mean by "VC++", which is merely an IDE) happily uses its central event dispatch system for all this stuff.

    To simulate, just have the loop run in a background, perhaps even daemon thread. Send accepts as events through your event system of choice.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    11

    Re: Client/Server App

    Plz can u explain more, i did not get what u want to say. or even how to write the event code!

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Client/Server App

    I'm saying that there is no general event mechanism in Java, so there can't be an onAccept event. You accept connections by calling accept() on a java.net.ServerSocket or java.nio.channels.ServerSocketChannel. If you have more than one server socket, you can also use java.nio.channels.Selector to do the main stuff. Point is, accepting is done by going into a blocking function call, and when it returns, you have a connection.

    Thus, to simulate an event, you have to have the loop. The loop can be in some background thread. The thread just calls accept() in a loop. Every time accept() returns, the thread does something with the new connection. If you want an onAccept event, then you need some event engine the thread can dispatch to. There is no such engine built-in into Java, but there may be libraries, and it wouldn't be too hard to write a simple one either.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width