Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Close ServerSocket from listening the port

Posted on 2001-09-17
3
Medium Priority
?
264 Views
Last Modified: 2006-11-17
I am writing chat program in peer to peer basic, which in the program i have serversocket function waiting to connect and also socket function to connect.which means 2 functions in one program.My question is how am i going to stop the listening port from keep on listening,when i intend to make connection, i try to put the serversocket.close method in the button to connect, which means if i intend to make connection, i will stop the port from listening.Please advice.
0
Comment
Question by:belim
[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
3 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 6487386
you must create several Threads.
0
 
LVL 1

Accepted Solution

by:
shekoff earned 600 total points
ID: 6487658
I  will tay to show a only the way to write your classes:
Class mainListener extends Thred
{
   public void Run()
   {
     ServerSocket oS = new ServerSocket .....
     Socket oSoc;
     ServereThred oThred ;
     while (true) // !!
     {
        oSoc = oS.accept();
        oThred = new ServerThred(oSoc);
        oThred.Start();
     };
   }
}
Class ServerThred extends Thred
{
  Socket oComm;
  public ServertThred(Socket oSock)
  {
    oComm = oSock;
    // with this socket you will comunicate with a client
  }

  public void Run()
  {
    //Making a comunication with a client
  }
}

I hope it will help to you !
Regards
0
 

Author Comment

by:belim
ID: 6502296
Thanks!
you deserved for it...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

610 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