Solved

Close ServerSocket from listening the port

Posted on 2001-09-17
3
260 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 150 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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.

707 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