|
-
Nov 25th, 2006, 10:30 AM
#1
Thread Starter
New Member
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.
-
Nov 25th, 2006, 01:25 PM
#2
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.
-
Nov 25th, 2006, 02:22 PM
#3
Thread Starter
New Member
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!
-
Nov 25th, 2006, 02:34 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|