A exception is generated in Windows but not in Linux

FULL PRODUCT VERSION :
junmin@Linux:~/Workspace/JMessenger/build/classes$ java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
E:\JMessenger\build\classes>java -version
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
junmin@Linux:~/Workspace/JMessenger/build/classes$ uname -a
Linux Linux 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686 GNU/Linux
ubuntu feisty, installed sun-java-jre and jdk from the repository of ubuntu
and
Windows XP professional sp2
java6 installed
A DESCRIPTION OF THE PROBLEM :
reader = new BufferedReader(new InputStreamReader(client.getInputStream())); // client is the socket in the server side
             try{
                 while((incomingMessage = reader.readLine()) != null){
             catch(Exception e){
                     System.out.println(e);
             }       //serverthis is a client-server program, why in Windows it(server) throw the Exception when the client closes the program o the socket? and it doesnt throw any exception in Linux(ubuntu feisty/dapper) ??????
here is the exception generated in Windows:
     java.net.SocketException: Connection reset
             at java.net.SocketInputStream.read(Unknown Source)
             at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
             at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
             at sun.nio.cs.StreamDecoder.read(Unknown Source)
             at java.io.InputStreamReader.read(Unknown Source)
             at java.io.BufferedReader.fill(Unknown Source)
             at java.io.BufferedReader.readLine(Unknown Source)
             at java.io.BufferedReader.readLine(Unknown Source)
             at Service.run(Service.java:37)is this could be considered a bug??? i hope java can throw the same exception in Linux too, cause this helps to check the statu of socket connection. thanks

The following is mostly an educated guess, but it is based in some understanding of how the different OSs work.
In linux sockets are handled by the driver(read: kernel part) that converts the actions on file descriptors to actions on network sockets. When a program shuts down, said driver continues to run, but receives a close request on the file descriptor, so it proceeds with a standard socket close.
On windows, the sockets are the property of the program, not the network driver, and when the program shuts down the sockets simply abort as they are discarded. The network driver is not allowed to temporarily hold the socket until its operation completes. They are simply thrown away.
Anyway, a proper solution that would be helpful for all OSs is to actually close the socket within the program, rather than hope the OS has a "garbage collector" for sockets. The same applies for all OS resources(files, pipes, GUI resources, etc). On certain OSs, certain resources may actually remain allocated after program shutdown, if not formally disposed.
On a side note, socket libraries for windows usually support socket auto-close on disposing of the socket object. I'm surprised the Java library doesn't (seem to) follow the same pattern. Then again, I've seen programs(non-java, of course) cause system freezes over stuff like that.

Similar Messages

  • URL.openStream() works in Windows but not in Linux

    I am having a problem with this line:
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    in the code sample further below.
    A simple program using this line works when compiled in my Windows XP:
    java version "1.6.0_03"
    Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
    Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
    but not when compiled on my RedHat FC 4 server:
    java version "1.4.2"
    gij (GNU libgcj) version 4.0.2 20051125 (Red Hat 4.0.2-8)
    The program (making using of a previous froum example and pared down to minimize tangent topics):
    The code works for all 3 URLs in Windows. In Linux it only works for the 1st one (bbc.co site)
    Error is listed below the code:
    import java.net.*;
    import java.io.*;
    public class BBC {
    public static void main(String[] args) throws Exception
    //    URL url = new URL("http://news.bbc.co.uk/sport1/hi/football/eng_prem/6205747.stm");
    //    URL url = new URL("http://www.weatherunderground.com/global/stations/71265.html");
        URL url = new URL("http://www.weatherunderground.com");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        int nLineCnt = 0;
        String inputLine;
        while ((inputLine = in.readLine()) != null)
            nLineCnt++;
        System.out.println("nLineCnt=" + nLineCnt);
    //--------------------------------------------------------------------------------------------------------------------------------------------Exception in thread "main" java.lang.StringIndexOutOfBoundsException
    at java.lang.String.substring(int, int) (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.net.protocol.http.Request.readResponse(gnu.java.net.LineInputStream) (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.net.protocol.http.Request.dispatch() (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.net.protocol.http.HTTPURLConnection.connect() (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.net.protocol.http.HTTPURLConnection.getInputStream() (/usr/lib/libgcj.so.6.0.0)
    at java.net.URL.openStream() (/usr/lib/libgcj.so.6.0.0)
    at BBC.main(java.lang.String[]) (Unknown Source)
    at gnu.java.lang.MainThread.call_main() (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)
    Can anyone please suggest what I can do to be able to process the weatherunderground URL?
    Claude

    To me it would suggest a bug in the VM that you are using.
    Solutions
    1. Use a different VM
    2. Write your own code to process the http code. Depending on licensing for the VM in use and the VM itself. you might be
    able to find the bug in that code, fix it yourself, and then use your fix (start up command line options for VM.) Otherwise
    you have to duplicate the functionality. You might look to jakarta commons, there might be code there that does that.

  • My codes run in windows but not in Linux what is wrong?

    //I have 4 codes in total but heres is one for example
    import java.util.*;
    // This state accepts numeric input less than 100 and subtracts
    // 1 from each input number before exiting the state.
    // We exit the state if the input is exactly 100.
    public class AState extends State {
    public AState (String n, boolean d ) {
    super(n,d);
    public void RUN () {
    int ch = 0;
    entry();
    Scanner stdin = new Scanner(System.in);
    ch = stdin.nextInt();
    while ( ch != 100 ) {
    ch--;
    System.out.print(" " + ch);
    ch = stdin.nextInt();
    // change state from AState to BState
    Controller.state = Controller.states[Controller.BSTATE];
    // this will be the AState version of exit().
    exit();
    //It runs perfectly in windows but once I compile in a terminal of Linux it doesn't run it show like 8 errors, why is that, can somebody tell me what can I do about it

    public class AState extends State {
    ^
    Astate.java:18: cannot find symbol
    symbol : method entry()
    location: class AState
    entry();
    ^
    ./Controller.java:8: class BState is public, should be declared in a file named BState.java
    public class BState extends State {
    ^
    ./Controller.java:8: cannot find symbol
    symbol: class State
    public class BState extends State {
    ^
    Astate.java:31: cannot access Controller
    bad class file: ./Controller.java
    file does not contain class Controller
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    Controller.state = Controller.states[Controller.BSTATE];
    ^
    6 errors
    //As i said before, this run perfently through windows the same exactly code.

  • Firefox works at mcdonalds with windows but not with linux

    I have Windows 7 Pro and Ubuntu 14.04 LTS on my laptop. I use firefox browser on both OS's. I am able to connect to internet when I use Windows OS and run firefox at McDonalds. But, when I try to use firefox and Ubuntu OS it will not connect while at McDonalds. Otherwise, the Ubuntu distro and firefox work fine everywhere else.

    ''bsluss [[#question-1051190|said]]''
    <blockquote>
    I have Windows 7 Pro and Ubuntu 14.04 LTS on my laptop. I use firefox browser on both OS's. I am able to connect to internet when I use Windows OS and run firefox at McDonalds. But, when I try to use firefox and Ubuntu OS it will not connect while at McDonalds. Otherwise, the Ubuntu distro and firefox work fine everywhere else.
    </blockquote>
    Thanks for the response. To narrow this down a bit more, the wireless makes the connection to their router, but, mozilla does not bring up the splash page that is needed to accept their connection. Again, it only happens when running firefox with Ubuntu; not when running firefox with Windows.

  • I have a dual-boot system on my laptop (windows/linux). Firefox opens on windows but not on linux (on linux firefox 'times out'). Why? and how do i fix this?

    could it be to do with the compatability being set to a windows setting?

    could it be to do with the compatability being set to a windows setting?

  • My iPod Classic is seen by Windows but not by iTunes.  I have reset it, gone to disk mode and it won't show up in iTunes.  There appears to be music on it in a file called MUSICSAVE.  How can I get this to work with iTunes again?

    My iPod Classic is seen by Windows but not by iTunes.  I have reset it, gone to disk mode and it won't show up in iTunes.  There appears to be music on it in a file called MUSICSAVE.  How can I get this to work with iTunes again?

    1. Update iTunes to the latest version. Plug in your iPod. If iTunes still can't recognize it, then in iTunes in the top left corner click help> run diagnostics. On the box that comes up, check the last two things. Click next and it should identify your iPod.
    2. Click on your windows start menu. Type in "services". Click on it and when it pops up, on the bottom of it click on "standard". Now Scroll down to find "Apple Mobile Device" Right click it when you see it and click on "Start". When it has started, close iTunes and replug in your iPod and it should show up.
    3. Check the USB cable
    4 Verify that Apple Mobile Device Support is installed
    5. Restart the Apple Mobile Device Service and verify that the Apple Mobile Device USB Driver is installed.
    6. If you just want to add some photos, songs and movies from computer to your devices, you can use an iTunes alternative to do the job
    7. Check for third-party software conflicts.
    <Link Edited By Host>

  • I upgraded to OS Yosemite on my MacBook Air...and I cannot upgrade the Adobe Flash download that Adobe keeps asking me to download. I get the screen and when I click on the icon it just creates a new window but not download. Thoughts?

    I upgraded to OS Yosemite on my MacBook Air...and I cannot upgrade the Adobe Flash download that Adobe keeps asking me to download. I get the screen and when I click on the icon it just creates a new window but not download. Thoughts?

    I just tried the link and it is just fine. If the GateKeeper pops up then open Security & Privacy preferences, click on the General tab, set the last radio button to Anywhere.

  • My phone is not showing up in itunes.  I want to sync it.  I have a MAC and I have restarted the phone, it's charged, I have the most current version of itunes.  What do I do now?  It says to reinstall itunes if you have windows but not for mac.  Help!

    My phone is not showing up in itunes.  I want to sync it.  I have a MAC and I have restarted the phone, it's charged, I have the most current version of itunes.  What do I do now?  It says to reinstall itunes if you have windows but not for mac.  Help!

    With your phone plugged in, open Image Capture and see if the iPhone shows up.  If not, you are having a sync problem.  If it shows up in Image Capture, but not iTunes, I'd delete iTunes and reinstall it.

  • Apple, Pfft!!! (Another iPod shows up in Windows but not in iTunes post)

    How in the world does Apple market the iPod, etc... as if 10-year olds and grandmothers can operate the technology, when having viewed these message boards for 10 hours yesterday, it seems as even the tech savy people who can make a computer out of two pieces of bread and a piece of bologna have to wrack their brains to make it come a step closer to actually working. Blah!!!
    Anyway, the problem that I am having is the problem that a lot of other people are having and seems to be the main theme at the moment.
    I am unable to have iTunes recognize my iPod. My PC will once-in-a-blue-moon recognize the iPod as its own drive in Windows Explorer, but mostly all I get is the big freeze. Every time I connect my iPod to the USB, all of the programs cease to operate until I unplug it. I am not having memory problems either.
    Here's what I've done. I have updated the iPod Updater to the 06-23-06 version. I was able to get it to update the software on my 60GB iPod. I got all excited only to then have it give me several error messages 1) an internal manager error and 2) some unable to dock or something like that (sorry I'm not at my home cpu.) Once while I was doing the 4-hour battery charge my iPod came up in the source list in iTunes, but I have been unable to have it be rerecognized.
    I've unistalled and reinstalled iTunes and the iPod Updater over 10 times and have gone through the 5 Rs as well as all of the steps on
    http://docs.info.apple.com/article.html?artnum=93716 (My iPod shows up in Windows but not in iTunes)
    I've even messed with msconfig and tried a whole bunch of other suggestions. It doesn't seem that Apple has a fix for this problem and we are all left with paperweights.
    Any suggestions?
    Thanks you all and condolences to everyone who is going through this same problem. I swear what happened to plug and play. Pfft!!!

    You know they are probably going to search me out and crash my computer for posting this but i had the same problem with iTunes. i spent hours, went through the 50000 "R's" and changed my settings and formatted and reset and reloaded and then i tried Realaudio. it found all the songs i had loaded into iTunes and put them on my shuffle first try. you can get Realaudio at <www.real.com> Let me know how it works...

  • IPod shows up in Windows but not in iTunes

    I have recieved a new IPod video 30Gb off my g/f (how nice of her :D) anyway when I plug it into my computer it will not appear in iTunes, a problem plenty of people are having it seems. The difference being I think I know what caused the problem but I'm having trouble with it still.
    When I recieved the Ipod I tried it on my girlfriends computer and it worked fine. She already had an ipod and itunes installed. I was able to add music no problem and it appeared in itunes. She however was having problems downloading on her computer for websites or using download sofware since installing itunes and the problem went away when itunes was uninstalled.
    Because of this (there were work arounds so I'm not after a fix for that) I thought I try using other software to see if that stopped me having this problem. This meant when I got my ipod home I plugged the ipod into my computer and did not install anything off the disc. This I believe is what has caused my problem for not being able to see my ipod in itunes.
    Anyway I tried to get other software to work (winamp at the time) but couldn't figure it out and so thought I'd just bite the bullet and install itunes and hope I didn't have the same problems as my g/f.
    After installing and plugging my ipod in again nothing happened. I checked My Computer and the ipod was there and called PHIL'S IPOD but nothing was in itunes. I then followed all the instructions on here :
    http://docs.info.apple.com/article.html?artnum=93716
    but it still won't pick up my ipod.
    Is there anything else I can try to get my ipod to appear in itunes I really do want to use it but at the minute I can't at all.
    Thanks in advance.

    Two years ago I had to return an ipod mini to the shop for a refund as I could not get it to work. It showed up in windows but not in itunes. I spent about a week trying EVERYTHING, blamed apple for some stupid glitch and gave up. Ten days ago my daughter got an ipod nano, and since we share the same pc I did warn her of what might happen. Yup, it did. Exactly the same problem. Once again I tried all the tricks, the five Rs, renaming the drive, you name it, I did it. Throughout this period though my PC was running a little slow and weird things were happening and despite using Norton Antivirus and other anti spyware I suspected I had not fully recovered from some sort of infection which drove me mad by blasting me with popups for 888 casinos etc. What I thought was really odd was that nothing showed up in Device Manager and having googled around a bit I came across this from which you can download a AproposFix.
    So if this sounds like your problem go here:
    http://www.dslreports.com/forum/remark,14679793
    and try it. The ipod now works, my daughter turned pink with delight, and my PC is now back to normal speed and all sorts of other seemingly unconnected annoyances have been resolved. I really do wish Apple could be more aware of problems like this as there seem to be many thousands of 'users' (ha ha) out there who look as if they are having similar problems.
    Dell Dimension   Windows XP  
    Dell Dimension   Windows XP  

  • IPod is recognized in Windows, but not in iTunes.

    Ive followed the support site on what to do if the iPod is recognized in Windows but not iTunes... but to no avail.
    ive had a 20GB photo thats been working o.k. (need to send it in) but now neither it nor my new 30GB Video will appear on iTunes... just in windows.... any suggestions? or should i just call up apple...
    p.s. i know its not the iPods cause they update fine on my sisters laptop...

    Does it say Cannot Mount iPod?
    Is the software on your computer up to date? You may want to try reinstalling it as well...
    iTunes
    iPod Updater
    Update iPod's Software
    Also, try right clicking on the iPod (in My Computer) and go to format. Does anything happen?
    btabz

  • TS1567 Iphone is recognized in windows but not itunes 11

    Iphone is recognized in windows but not itunes 11

    Use the article for this issue
    http://support.apple.com/kb/TS1538

  • New IPhone 5 is recognized by Windows but, not ITunes.

    IPhone 4S sync'd no problem with my laptop.  New IPhone 5 is recognized by Windows but, not ITunes.  ITunes has been updated, worked with Apple support for 2 hours this morning, still an unresolved problem.  Also, phone does sync on other computers.

    Hi there,
    I would recommend taking a look at the troubleshooting steps found in the article below.
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    -Griff W.

  • My ipod is recognized by windows but not itunes

    Ok, I had trouble with my 4gb black nano when I had to install it, i used TrevorQ's tip and it worked.
    Now I need to update some songs on my ipod and it wont recognize it now
    6.05.20 Itunes
    2006-03-23 Ipod Updater
    I cant end the "IpodService.exe" process

    See if anything here helps: iPod shows up in Windows but not in iTunes

  • Ipod is recognized by windows but not itunes

    i got a 4gb nano and when i connect my ipod to my computer it dosnt show up in itunes i reinstalled everything but it still wont work

    hiya!
    okay, we'd better check through the usual suspects:
    iPod for Windows: Fast user switching in Windows XP is not supported
    iPod shows up in Windows but not in iTunes
    love, b

Maybe you are looking for

  • Unable to partition drive for Boot Camp / Windows XP installation

    I need to install Windows XP on my MacBook so that I can run MS Access 2007 for an online college course I'm taking. When I attempt to partition (it doesn't seem to matter what size I choose to make the Windows partition), I get a message that the "T

  • Connecting os9 G3 to 10.3 G4

    First I would like to thank everyone for the help on (help or I'm going pc) quick up date I had to erase HD and install osx 3 times before i got a clean install. Yea os9 was long gone. all i can say is +REPAIR PERMISSION+ and do it again. and wow tha

  • How to install whatsapp on Ipad mini

    whatsapp Ipad

  • Finding tables used by transaction CM29

    Hi guys, I have to create a report with information from transaction CM29 (Planning table SAPPI_G001). The report must list all orders scheduled for a resource (orders in the 'Resources' area) in a period. My problem is to find the tables where that

  • Z61p - Clear security Chip settings

    How do I clear the security Chip settings on my Z61p? I have looked in Bios and Client Security but can not see a 'Clear' option? Peter R Hawkes