Solved

Close ServerSocket from listening the port

Posted on 2001-09-17
3
252 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_
Comment Utility
you must create several Threads.
0
 
LVL 1

Accepted Solution

by:
shekoff earned 150 total points
Comment Utility
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
Comment Utility
Thanks!
you deserved for it...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now