Solved

Single Java Socket

Posted on 1998-07-07
2
194 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 11 49
Why my table column Id is not passed to java object? 4 44
servlet example 17 53
ejb mdb examples 1 9
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

828 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