Solved

Close ServerSocket from listening the port

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

740 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