Solved

Close ServerSocket from listening the port

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

820 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