Welcome to Dream.In.Code
Become a Java Expert!

Join 150,413 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 983 people online right now. Registration is fast and FREE... Join Now!




Server Sockets

 
Reply to this topicStart new topic

Server Sockets

clatcho
3 Apr, 2008 - 07:42 AM
Post #1

New D.I.C Head
*

Joined: 14 Feb, 2007
Posts: 32


My Contributions
How would you test to see if anything was actually connected to a serverSocket ?

I have a program that constantly listens for connections, a client will connect to it, do what it needs to do, but the server then waits for the next connection.

What i need to be able to do is say IF NOTHING IS CONNECTED then perform action ELSE perform other action
User is offlineProfile CardPM
+Quote Post

pbl
RE: Server Sockets
3 Apr, 2008 - 08:25 AM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(clatcho @ 3 Apr, 2008 - 08:42 AM) *

How would you test to see if anything was actually connected to a serverSocket ?

I have a program that constantly listens for connections, a client will connect to it, do what it needs to do, but the server then waits for the next connection.

What i need to be able to do is say IF NOTHING IS CONNECTED then perform action ELSE perform other action


As 1lacca would say:

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Put your code between code tags.

But I guess we can go with pseudo code


Basically I don't think that
if(nothing is connected) {
do something
}
else {
do something else
}

is a good idea... you will loop an burn CPU time when nothing is connected

the real way is

for(;;) {
wait for connection
start a thread to handle the connection
}


User is offlineProfile CardPM
+Quote Post

clatcho
RE: Server Sockets
3 Apr, 2008 - 09:27 AM
Post #3

New D.I.C Head
*

Joined: 14 Feb, 2007
Posts: 32


My Contributions
cheers, didn't really want to post the code as it is for Uni and would only be cheating myself if someone showed me the code.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:46PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month