Stream connection throws IOException

i am using a stream connection for the midp 1.0. The client logs into a server using a StreamConnection and all this is cool.
But the application waits at the DataInputStream.read and then thows the IOException.
my code is something like this,,
while(true)
if ((i = dataInputStream.read()) == -1)
// some logic here
the dataInputStream.read() throws the exception after approximately 7 to 8 seconds.
anyone has an idea as to whats going wrong? why is the connection not being maintained.
Thankyou,
Balaji.

Thankyou shmoove. The code is here.
The server is setup to send information every 3 seconds to the client (upon client request,, which is working fine). For your reference,, the same code works perfectly fine with a Series 60 (midp2.0) phone, and so does the server. except that i use a SocketConnection for the midp 2.0 phone. For the very reason that midp 1.0 does not support the SocketConnection, i have to use a StreamConnection instead. the dataInputSream is bound with the StreamConnection object.
I think the StreamConnection is somehow not persistant ,, in the sense the connection is not maintained.
Please tell me whats wrong,
Thankyou,
Balaji.
public Alert alertConnBroken = new Alert("", "Due to weak wireless link, Connection to server lost. Please reconnect!!", null, AlertType.WARNING);
public String readString()
     String str = new String();
     while(true)
          try
               if((ch = (char) dataInputStream.read()) == -1)                   
                    display.setCurrent(alertConnBroken);
                    break;
               else
                  str = str + ch;
          catch(InterruptedIOException iioe)
               iioe.printStackTrace();
               break;
          catch (IOException ioe)
               ioe.printStackTrace();
               break;
            catch(EOFException eofe)                     
                eofe.printStackTrace();                                        
             break;
         catch (Exception e)
            e.printStackTrace();
             break;
     return str;     
     

Similar Messages

  • JarURL.openStream() throws *IOException: no entry name specified*

    <pre>
    I have some code (supplied below) which tries to read contents of a resource
    referred by a URL.
    public class URLTest {
    public static void main(String... args) throws Exception {
    URL u = new URL(args[0]);
    InputStream is = u.openStream();
    // more code goes here:
    If you create a jar file in /tmp/b.jar and run this program as shown below:
    (If your shell treats ! as a special char, then you need to use escape char \ before it)
    java pkg.URLTest <b>jar:file:/tmp/b.jar!/</b>
    it produces the following exception:
    Exception in thread "main" java.io.IOException: no entry name specified
    at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:131)
    at java.net.URL.openStream(URL.java:1007)
    at pkg.URLTest.main(URLTest.java:20)
    But, if you pass the argument as jar:file:/tmp/b.jar!/A.class then it opens a stream
    that points to A.class which is embedded inside b.jar.
    My question is, what is the motivation behind not allowing user to open a stream to
    jar:file:/tmp/b.jar!/ which according to the javadocs of JarURLConnection
    http://java.sun.com/j2se/1.5.0/docs/api/java/net/JarURLConnection.html
    represents a JAR File?
    Thanks,
    Sahoo
    </pre>

    I just also came across this. I don't know the motivation behind it. But it is certainly deliberate.
    This is the source code for JarURLConnection.getInputStream.
    public InputStream getInputStream() throws IOException {
         connect();
         InputStream result = null;
         if (entryName == null) {
              throw new IOException("no entry name specified");
         } else {
              if (jarEntry == null) {
                   throw new FileNotFoundException("JAR entry " + entryName +
                        " not found in " +
                        jarFile.getName());
              result = new JarURLInputStream (jarFile.getInputStream(jarEntry));
         return result;
    }So it will only let you get an InputStream to a file inside the Jar file, not the Jar file itself.
    If you want to do that, then rather than using InputStreams you want to use the JarURLConnection class. My example below shows you how to get at the JarFile and its contents, JarEntry objects,
    URL u = new URL("/tmp/b.jar!/");
    JarURLConnection juc = (JarURLConnection)u.openConnection();
    JarFile jf = juc.getJarFile();
    System.out.println("JarFile: " + jf.getName());
    Enumeration<JarEntry> entries = jf.entries();
    for(JarEntry je = entries.nextElement(); entries.hasMoreElements(); je = entries.nextElement())
         System.out.println("\tJarEntry: " + je.getName());
    }

  • Closed TCP connection throws "Address already in use:connect"

    Hello,
    I am writing a deamon that has to connect to a server from a well-specified local port number.(very imp. constraint)
    Evry time I have to write something on server's output stream I do:
    public synchronized void sendMsg(byte[] msg) throws IOException {
         //#1
         clientSocket = new Socket();
         clientSocket.setReuseAddress(true); //so i can bind even when in TIME_WAIT
         clientSocket.setKeepAlive(false); //optional, but i guess no harm here
         clientSocket.bind(localSocketAddress); //local address is correct
         clientSocket.connect(hostSocketAddress); //.. and so is the host address
         //#2
         clientSocket.getOutputStream().write(msg);
         clientSocket.getOutputStream().flush();
         clientSocket.shutdownOutput();//optional..
         clientSocket.close();// so I DO close the socket
    After the 1st successfull attempt to write to the server,
    a call to sendMsg(..) is throwning a "Address already in use: connect" IOExc.
    The problem comes from clientSocket.connect() but that's odd since I closed the socket in earlier call..
    I think the physical connection is not closed, although the clientSocket.close() returned..
    So I put the code from //#1 to //#2 into a loop that catches the exception, attempts to close and sleeps
    for a while(1 sec).. but no use! it seems looping forever...
    Is there a way I can force the connection be closed so I can create a new one safely?
    [I can't reuse the same connection for multiple calls - it's ugly and the server may close it anyway..]
    Any hint, ideea?
    Thank you
    L

    1st becasue it's ugly to maintain a connection for
    daysYes. But it is also ugly to continuely close and open a socket.
    The solution is to add a timeout which closes the connection if it has not been used for a certain amount of time.
    2nd because the server may close it [and i can't stop
    him for doing that]
    So you add retry logic. But given that you are using TCP you must be guaranteeing delivery so you have to have retry logic if the server isn't up in the first place right? The same logic is used if the connection has failed.

  • On Windows 7 HttpURLConnection.openConnection() throws IOException

    Hi Team,
    In our application we have a to create httpURLCOnnection (url.openConnection())which works fine on Windows XP but throws IOException on Windows7. Does anybody know which settings need to be enabled on windows 7 to resolve this issue?
    Any response would be appreciated. Thanks in Advance.

    Hello Team,
    I have a specific exception which I get when trying to open a url on Windows 7 with IIS authentication enabled. We get exception when trying to get response code of HTTP Connection
    java.io.IOException: Authentication failure
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    Same code works find on windows XP. Do I need to do any specific settings on Windows7 to work this?
    Thanks in Advance.

  • SocketChannel.write() throws IOException instead of returning 0

    I would like your opinion.
    When a send buffer is full in the OS, should a channel's write()
    return 0, or throw an exception? If an exception, should it be the
    same exception (IOException) thrown when truly exceptional events
    happen (e.g, a connection drop)?
    On Win32, SocketChannel.write() internally calls WSASend(). When
    WSASend() returns WSAEWOULDBLOCK, write() throws IOException. I
    think it should return zero instead, or at least throw an exception
    that can be distinguished easily (by other than parsing the
    IOException.getMessage())
    Should I submit a bug?
    Thanks,
    Juan

    The java doc for write() says it should return zero. If you have a simple test case that demonstrates the behavior you describe and it is not already in the bug database, then yes. You should file the bug report.

  • DOMparser throws IOException when encounters Hungarian Characters

    Hoi!
    I wrote a piece of code that extracts some
    information from an XML document into a vector of Java classes, using the oracle.xml.parser.v2.DOMParser.
    And it worked. Or seemed to work...
    But when I put some articles in the XML file
    in Hungarian, the parser threw IOException.
    If I remplace the Hungarian characters to
    English "equivalents" a -> a etc., it works.
    I don't know. If XML is made up of Unicode characters, what's the problem with it?
    (The hex code of a was E1 in my text editor,
    as I'm using Win NT :(. )
    can I modify the xml prolog somehow?
    I'd rather not write a conversion program
    from a text file to another.
    Any ideas?
    and here's the code:
    DOMParser theParser = new DOMParser();
    XMLStreamToParse = XMLes.class.getResourceAsStream(xmlDocPath);
    theParser.setValidationMode(false);
    try{
    theParser.parse( XMLStreamToParse );
    //this throws IOException
    null

    What are you using as your test client?The test client is WebStone 1.0. WebStone always downloads the whole response, and reports the size of the response in bytes. From this I can see that when the IO exception occurs, webstone is unable to read the whole response, as it reports a smaller size.
    So, I do not think the problem is that the client has prematurely aborted its download. WebStone doesn't work that way. I think something has gone awry on the server side, and this worries me.

  • I am not able to see images in Facebook while i am connecting throw wifi

    I am not able to see images in Facebook while i am connecting throw wifi

    Hello amitkcindia,
    I would recommend verifying your WiFi router's settings against our recommendations for use with iOS and Mac OS devices.
    iOS and OS X: Recommended settings for Wi-Fi routers and access points
    http://support.apple.com/kb/HT4199
    Cheers,
    Allen

  • Multiple Consumer Object per Streaming Connection in AIR2.0

    HI,
    we require streaming server setup for our project.
    We are trying to minimize number of connections to the streaming server.
    My query is "If we have multiple Consumer object instance with same channel and destination, will all the Consumer instances share the same streaming connection or for every Consumer object instance a new Connection is created?"
    Thanks in advacne for your support.
    Regards,
    Shailendra

    Thanks doghouseJim, appreicate
    I tried to substitute onStatus function with your code (metadata) and as a result I don't have reported  error anymore.
    However, for strange reason, once the flash goes into a html document the video is not loaded...
    any idea?
    Cheers

  • If 2 clients can't be neighbours can they establish a direct stream connection?

    I used to have 2 computers (connected over a strange network) that could not become neigbours in the same NetGroup!
    Because of that I am now exchanging the farID's trough the database similar to the Cirrus sample (I used to exchange it trough the NetGroup).
    But now I find that even a direct stream connection between the same computers is not really possible!
    So, if 2 clients can't be neighbours is there any chance they can establish a direct stream connection?

    no.  exactly the same kind of RTMFP connection is attempted between the two computers.  direct connections and group communications are just different kinds of flows over an RTMFP session.

  • Throws IOException

    What is a best way to write throwing IOException here?
    Can I write try-catch, and after "catch" throw it?
    Is this right?
    I have no idea how to do it with if-clause.
    /** Writes the given apartment data in the file. If the file already
    exists, the old contents are overwritten.
    Parameters:
    apartment - the apartment to be written in the file
    Throws:
    IOException - if other problems arose when handling the file (e.g. the
    file could not be written) */
            public Appartment writeAppartment(Appartment appartment)
                  throws IOException {
                 try {
                    writeStream = new FileOutputStream(filepath);
                    objectStream = new ObjectOutputStream(objectStream);
                    objectStream.writeObject(appartment);
                 } catch (Exception e) {
                   String message ="Writing to file "+filepath+ " failed.";
                   throw new IOException(message);
    }

    Since your method is defined as "throws IOException", why not just get
    rid of the whole try/catch block. Let the caller of writeAppartment
    catch it. You don't seem to be doing anything special with the
    exception when your throwing it, like throwing a custom one, so just
    let java throw it. Plus, what if there is a NullPointerException...it
    would be thrown as an IOException?I see, I haven't understood that when the method is defined as
    "throws IOException", it throws it "automatically".
    So I haven't to do anything.
    But when I call this "throws-method" I have to catch the Exception or
    throw it forward.
    Is that right???
    was meant to be:
    objectStream = new ObjectOutputStream(writeStream);jep, sorry there was an error in that line.

  • If I delete all the pics n movies from camera roll.r they gonna b deleted from iCloud as well?n is photo stream connected to iCloud?

    If I delete all the pics n movies from camera roll.r they gonna b deleted from iCloud as well?n is photo stream connected to iCloud?

    Welcome to the Apple Community Hamza.
    Firstly, photo stream doesn't save videos, secondly, it may not have all your photos saved in it, it only keeps photos for 30 days.
    Back up your photos to a computer or online photo storage facility, before deleting them from your phone.

  • Increasing max-streaming-connections-per-session has slow acknowledge response?

    Our application is a Flex GUI with a WebLogic Server (BlaseDS) on a private network.  We were originally using IE 6, but have upgraded to IE 8.
    I am trying to use publish/subscribe messaging to monitor lengthy processes on the server and received incremental data.  With 1 such process everything works fine.  But we want to allow the user to subscribe to more than 1 message destination.  So I increased the "max-streaming-connections-per-session" (default is 1) in the services-config.xml file
         <channel-definition id="process-notification-streaming-amf"
              class="mx.messaging.channels.StreamingAMFChannel">
              <endpoint url=https://{server.name}:{server.port}/{context.root}/messagebroker/streamingnotificationamf"
              class="flex.messaging.endpoints.StreamingAMFEndpoint"/>
              <properties>
                   <user-agent-settings>
                        <user-agent match-on="MSIE" kickstart-bytes="2048"
                             max-streaming-connections-per-session="3" />
                   </user-agent-settings>
              </properties>
         </channel-definition>
    If we leave max-streaming-connections-per-session as the default value of 1 and try to subscribe to another message destination we get an error indicating limit has been reached:
         [BlaseDS]Endpoint with id 'process-notification-streaming-amf' cannot grant streaming connection to FlexClient with id '7FFC82DE-etc ' because max-streaming-connections-per-session limit of '1' has been reached.
         We upgraded to IE8 as documentation indicates IE8 allows for an increase of max-streaming-connections-per-session, where IE 6 is limited to 1.  But increasing max-streaming-connections-per-session does not quite solve the problem.  We have 3 consumers; consumer1, consumer2, consumer3.  For each of these consumers, we add event listeners for MessageAckEvent.ACKNOWLEDGE and MessageEvent.MESSAGE.
         We call consumer1.subscribe().  When we receive the acknowledge message, we call consumer2.subscribe() (likewise with consumer3)
         The problem is it takes over 2 minutes to receive the acknowledge message from the call to consumer1.subscribe().  (With max-streaming-connections-per-session set to 1, the acknowledge message is received in a few seconds.)
         So, increasing max-streaming-connections-per-session removes the error about reaching a limit, but it appears to come with a cost of a big delay in a long delay on the call to subscribe?  Or is there something we are missing?

    I guess I will answer my own question.  Hopefully this will be useful to someone else in the future...
    The problem was coming from IE being limited to 1 connection by the registry.  The solution can be found at:
    http://support.microsoft.com/kb/282402
    I manually performed the steps to update the registry, though microsoft provides a "Fix It"; MicrosoftFixit50098.msi
    One other key element was to make sure to have kickstart-bytes="2048".

  • Max streaming connections per session error

    I have a flex application that uses messaging with a streaming AMF connection, falling back to polling. When the max number of streaming connections on the server is reached, it does fall back to polling (at least it prints the max-streaming-clients error but the client connects, so I assume it is falling back - how can I tell?). However, occasionally the streaming connection will not initialize and it does not fall back - no messages are received on the client. The following error is logged on the server:
    [EMST]09/25/2008 13:43:18.231 [ERROR] Endpoint with id 'my-streaming-amf' cannot grant streaming connection to FlexClient with id 'D5B8E3A1-1A1C-063E-84A6-6A743A1E4EE0' because max-streaming-connections-per-session limit of '1' has been reached.
    This would make sense if the issue was caused by trying to initialize the streaming connection in two tabs of a browser, but I am only trying to initialize in one tab. Closing the browser (and thus destroying the session) does not fix it. The only solution I've found is to reboot the client machine. This has happened in both FireFox 3.0.2 and IE 7.
    (1) What could cause the client to get in this state?
    (2) When it happens, why doesn't it fall back to polling? Is the fallback only for when the server max connections is reached? When the streaming connection doesn't initialize, no messages are received.
    (3) Is there a way to explicitly close the streaming connection on the client so we can fix this without rebooting?
    Thanks!

    Hi Mary. If you turn on Debug level logging on the client and the server you should be able to tell if you have fallen back to a polling channel after the attempt to connect over the streaming channel has been rejected. In the client log, you will see the flex application sending poll requests to the server at the polling interval configured in the channel and in the server log you should see that the server is receiving these requests.
    The behaviour you are seeing seems very strange to me. The reason we have the max-streaming-connections-per-session limit on the server is because most browsers limit the number of active connections that can be made to a server from a single session. In IE for example, this is 2. What happens in most cases when the browser's connection limit is reached is that new connections are put on hold until one of the existing connections closes. This would cause your flex application to hang with no errors being reported on the client or the server. This is why we need the max-streaming-connections-per-session setting on the server. This prevents more than one persistent connection from being made from the same session, so the browser should never reach it's max connections per server limit and lock up.
    It looks like you are somehow getting the browser to lock up even though the server is only limiting you to one streaming connection per session. It may be possible to do this if you reload the flex application in the browser (by doing a page refresh) in which case the browser could possibly briefly leave the streaming connection open in the background and when you tried to create a new streaming connection, the browser's connection limit to the server would have been reached and the application could hang. When the application hangs are you reloading the swf/page in the browser?
    I really don't know why closing the browser wouldn't fix the problem. You're right that closing the browser should end the session. If you launch a new browser and load the swf do you get the same "cannot grant streaming connection" error on the server or is the browser just locked up, ie. no error is received on the client and the server?
    You're not using a proxy server or anything like that are you that might be holding a connection open to the server?
    -Alex

  • Max-streaming-connections-per-session limit

    Hello,
    i'm trying BlazeDS with Air app.
    I set blazeDs on a Jboss Server with JMS adapter.
    I configure it with a streamingAMF channel.
    In user agent configuration i put msie, firefox value to 10 for the max-streaming-connections-per-session limit param.
    In Air client configuration i instantiate a producer and a consumer on the same streaming AMF channel.
    After the consumer.subscribe() i launch the producer.connect() on the server i get this error :
    14:25:20,015 INFO [STDOUT] [BlazeDS] Endpoint with id 'my-streaming-amf' cannot grant streaming connection to FlexClient with id '497031A2-7B0D-019A-0E1D-7622A-A631D28' because max-streaming-connections-per-session limit of '1' has been reached.
    Is it a limitation of use of blazeDs with Air app ?

    First, if you change the limit to 10, then it should be 10 and not 1. If you still see 1, then please log a bug.
    Second, you really want this limit to be 1 in IE and 4 in Firefox 2. But there's no reason to have more than 1 streaming connection from the server to the client unless you need to talk to two different endpoints.

  • Log API: StreamHandler.flush() throws IOException ?

    For some network error reason, my logging stopped working and i noticed this exception in the console:
    java.util.logging.ErrorManager: 2
    java.io.IOException: The specified network name is no longer available
            at java.io.FileOutputStream.writeBytes(Native Method)
            at java.io.FileOutputStream.write(Unknown Source)
            at sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(Unknown Source)
            at sun.nio.cs.StreamEncoder$CharsetSE.implFlushBuffer(Unknown Source)
            at sun.nio.cs.StreamEncoder$CharsetSE.implFlush(Unknown Source)
            at sun.nio.cs.StreamEncoder.flush(Unknown Source)
            at java.io.OutputStreamWriter.flush(Unknown Source)
            at java.util.logging.StreamHandler.flush(Unknown Source)
            at de.icp.logging.RollingFileHandler.publish(Unknown Source)I looked into the javadoc of StreamHandler.flush() and can't find any documented Exception that is thrown. As IOException is not an unchecked exception, this seems to be a javadoc bug, right?
    My "RollingFileHandler extends StreamHandler and my publish() looks like this:
         * Overwrites super.
        public synchronized void publish(LogRecord record) {
            if (!isLoggable(record)) {
                return;
            //check if we need to rotate
            if (System.currentTimeMillis() >= nextCycle) { //next cycle?
                role();
            super.publish(record);
            flush(); //throws IOException ??????
        }//publish()

    Hm ... i think overwriting reportError() is useful:
         * Overwrites super.
         * Reopen log file in case of an error.
        protected void reportError(String msg, Exception ex, int code) {
            super.reportError(msg, ex, code); //standard behaviour of Handler
           //on logging error, try to reopen the logfile:
            openFile();
            LogRecord record = new LogRecord(Level.WARNING, "Log file re-opened due to error:");
            record.setThrown(ex);
            publish(record);
        }//reportError()

Maybe you are looking for

  • #(hash) sign printed out for spaces material description in PO

    Hi All, I have problem with my sapscript form for PO, when preview, the material description is ok but when print out,  the space between the word of the material description become # sign like Leif#Eriksson#1oz#Silver#Coin###, this not happen to all

  • Newbi Question:  How does one create a similar page to this using APEX 3.1?

    Hi, I am trying to create a help document with screen shoots inside our APEX web application and I am hamstrung by the type of Region and Item objects available to me. When I tried to create HTML region I was limited to how much html characters I can

  • Intel Mac Mini, Firefox and Java

    I'm running an Intel Mac Mini using Firefox; mostly it's fine, but sometimes it behaves as if it and Java Applets have had a falling out. I have made sure that I have the very latest version of JRE to go with OSX, but when I go to http://www.f1.com a

  • Update Text Field with Vendor Account

    Dear Experts, I have a requirement where the user when executes APP F110 the field Text of the Bank Line Item should get updated with the Vendor Account Name so that whenever User executes GL Line Item Display for Bank Clearing Account user should ge

  • Encore 6 application does not open

    I have CS6 master collection installed on my PC, but after getting an 'internal error' message while working in encore 6, the application no longer opens. Can it be repaired? Do I have to reload it? How do I do that when it is no longer an active pro