Solved

Single Java Socket

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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 …
Suggested Courses

752 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