Yong,
        I tried your program with little change which I am sending that,
the port which is in already  in use will  print 0,(that's what I think) ,
try this it will print your port number
import java.net.*;
import java.io.*;

public class UsersServlet
{

   static int SERVLET_PORT=10000;
   public static void main(String args[])
   {
     try
     {
         ServerSocket serverSocket = new ServerSocket(SERVLET_PORT);
         System.out.println(serverSocket.getLocalPort());
         ServerSocket rSocket = new ServerSocket(SERVLET_PORT);
         System.out.println(rSocket.getLocalPort());
     }
     catch(Exception e)
     {
     }

   }
}
Thanks for your problem,
vijaya
> ----------
> From:         Yong Hu[SMTP:[EMAIL PROTECTED]]
> Reply To:     A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology.
> Sent:         Friday, October 08, 1999 5:12 PM
> To:   [EMAIL PROTECTED]
> Subject:      Re: About BindException
>
>   Thanks,with your help,I has resolved that question.I close the
> serversocket in destroy() method and it works well.
>
>   Howerver I meet with another question.I want to know if the serversocket
> is my hope beacause the applet can't talk with servlet
> well.Then after create the serversocket on port 10000,I use
> serversocket.getLocalPort() to see the real value,but it return 0.I
> don't know why i get this value.
>
> Thanks advanced.
> Huyong
>
>
> > >
> > > The following is the code:
> > >
> > > public class UsersServlet extends HttpServlet implements Runnable{
> > >
> > >   static int SERVLET_PORT=10000;
> > >
> > >   ServerSocket  serverSocket;
> > >
> > >   RandomAccessFile myfile;
> > >
> > >   Thread mythread=new Thread(this);
> > >
> > >   public void run(){
> > >     try{
> > >         serverSocket = new ServerSocket(SERVLET_PORT);
> > >         myfile=new RandomAccessFile("c:\\temp\\servlet.txt","rw");
>             myfile.write(serverSocket.getLocalPort());
>             myfile.close();
> > >         while (true)
> > >            handleClient(serverSocket.accept());
> > >          }catch(IOException e){}
> > >
> > >
> > >   }
> > >
> > >   public void init(ServletConfig config) throws ServletException {
> > >         super.init(config);
> > >         mythread.start();
> > >
> > >   }
> > >
> > > public void handleClient(Socket client){
> > >     new UserConnection(this, client).start();
> > >
> > > Any suggetion is helpful to me.
> > >
> > > Regards
> > > Huyong
> > >
> >
> >_________________________________________________________________________
> __
> >To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> >of the message "signoff SERVLET-INTEREST".
> >
> >Archives: http://archives.java.sun.com/archives/servlet-interest.html
> >Resources: http://java.sun.com/products/servlet/external-resources.html
> >LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
> __________________________________________________________________________
> _
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to