The Artima Developer Community
Sponsored Link

Java Answers Forum
Is it because of Windows?

5 replies on 1 page. Most recent reply: May 15, 2002 3:23 PM by Thomas SMETS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Tarba Dan

Posts: 11
Nickname: dtarba
Registered: May, 2002

Is it because of Windows? Posted: May 13, 2002 1:24 AM
Reply to this message Reply
Advertisement
I have a very weird problem . I have written a piece of code where I use a ServerSocket . Under Windows 2000 all works perfectly but when I'm running the code under Windows 98 I get a IOException . It seems that there is some problem accessing the ports but I don't know why. Thank you.


Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Is it because of Windows? Posted: May 13, 2002 2:43 PM
Reply to this message Reply
What is the port ?
Could you give us a idea of what you do with the ServerSocket ?

Tx,

Thomas SMETS,
SCJP2 - Brussels

Tarba Dan

Posts: 11
Nickname: dtarba
Registered: May, 2002

Re: Is it because of Windows? Posted: May 14, 2002 4:46 AM
Reply to this message Reply
When you use a ServerSocket you must specify the port it works on( ServerSocket(int port)) . I'm using the Server Socket to create a chat server .

I don't remeber exactly the code but
it looks very much like this

//here I get an exception :

ServerSocket ssock = new ServerSocket(port)

//I have tried a lot of values for port
...
while(true){
...
try{
socket = ssock.accept();
...
//launch the thread for serving the client..
}catch(...){}
...
}

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Is it because of Windows? Posted: May 14, 2002 9:43 AM
Reply to this message Reply
What is your OS ?
What are the value ranges you tried ?

Having the code herebelow, you will realize that on a decently configure Unix machine it will never work !
_ Basically port have positive values (just in case!)
_ Ports between 1 & 1023 are under "root" control, hence possible problem. Also your machine may itself run different services which are locking a port (hence an exception)

I would be an idea but please don't feel oblige to simply post the exception trace you have when requesting help. May be not the 200 lines - if there is... - but it's generally speaking a good idea to help "us" working out what you prroblem is (if that's the point ?)

Thomas SMETS,
SCJP2 - Brussels

As an example the code here below should never work !
//here I get an exception :
ServerSocket ssock ;
for ( int i = -1000; i < 1000; i++)
{
  try
  {
    ssock = new ServerSocket(port) 
    break;
  } catch (IOException ioe)
  {
  }
} //I have tried a lot of values for port
...
while(true)
{
...
try
{ 
  socket = ssock.accept();
...
//launch the thread for serving the client..
}catch(...)
{}
...
} 

Tarba Dan

Posts: 11
Nickname: dtarba
Registered: May, 2002

Re: Is it because of Windows? Posted: May 15, 2002 2:27 AM
Reply to this message Reply
I usually work on port 8353 but I also tried values between 2000 and 25000 . It doesn't work under Windows 98 on any of them .

My OS is now Windows 2000 . I've installed it because I have this problem with Windows 98.

I would like you to tell me if you tried to create a ServerSocket under Windows 98.If you did please tell me if it worked well .

The problem is that I don't know where the error comes from .

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Is it because of Windows? Posted: May 15, 2002 3:23 PM
Reply to this message Reply
Open a Dos-box & type in it "netstat -a" & look if there is any port "locked" by the system (there shouldn't be).

With the command : "netstat -a" you may even type "netstat -a n" with n being an integer between say 2 & 10 (refresh rate in secs).

You could also comb the port-range with a piece of code similar to the one I have written to have the available ports ?

Thomas SMETS,
SCJP2 - Brussels

Flat View: This topic has 5 replies on 1 page
Topic: drop down boxes Previous Topic   Next Topic Topic: position staying at 0

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use