Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Single Java Socket

Posted on 1998-07-07
2
Medium Priority
?
217 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 400 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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

715 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