Solved

Single Java Socket

Posted on 1998-07-07
2
207 Views
Last Modified: 2010-04-16
I have a Client/Server Java application written and working via a Socket.
Now what I want is for only ONE connection to be allowed to this socket.
How can I code it so that only one user can access the Server Socket at a time?
I have tried:
kkSocket = new Socket("rock", 5555,1);
But it is not doing anything when two people connect at the same time.
Thanx!

Don
0
Comment
Question by:afsac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 100 total points
ID: 1225204
My guess, you control that behavior on the ServerSocket side. When you create a server socket you have to call serverSocket.accept() before client sockets can connect to it. Usually this is done in a loop where you accept a connection, spawn a separate thread to process it and continue listening. In your case you call accept() (which blocks the thread) and then connection comes in you stop listening (by not calling accept() again, or call accept() only after the existing connection is closed).

If that does not work, you can provide some application level logic where you count number of incoming connections and after establishing one connection you reject all the subsequent ones until that one disconnects.
0
 

Author Comment

by:afsac
ID: 1225205
I've been looking at the server side. As of now I don't have it doing what
I want.  But I see what you are talking about.  I'll keep working it, I think
that I can make it happen.  Thanx!

Don
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question