×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    53

    Question Fatal: IO Error:SymbainOS error = -34 : General: System error

    Hello there,


    How can I tell if my TCP/IP connection is CLOSED prior to Connection?

    I am connecting to a fixed IP and Port using: SocketConnection, the first two sessions are fine, but the following sessions result in:

    "Fatal: IO Error:SymbainOS error = -34 : General: System error"

    I fell that the IP and port are not compleately closed following the previous connection. I have placed my disconnect routine into a thread, and so that I can wait for the disconnection to end before I attempt another connection.

    If I attempt a re-connection after 1-2 minutes it appears to connect successfully.


    Here is the code I am using to make a connection and disconnection:


    Code:
    public class Connection extends ConnectionStatus implements  Runnable {
    
        public static Connection instance = null;
    
        public byte ConnectionStatus = DISCONNECTED;
    
        /** String constant for the socket address */
        private static final String SOCKET_ADDRESS = "socket://";
    
        /** instance of SocketConnection */
        private SocketConnection socketConnection = null;
        private InputStream InStream  = null;
        private OutputStream OutStream = null;
    
        private ConnectionDetails connectionDetails;
        
        // Connect Discaonnect flags:
        private final byte CD_UNKNOWN = 0;
        private final byte CD_CONNECT = 1;
        private final byte CD_DISCONNECT = 2;
        private byte ConnectDisconnectFlag = CD_UNKNOWN;
    
        public static Connection getInstance(ConnectionDetails CD, Form form, Display disp) {
            if(instance == null)
            {
                instance = new Connection(CD, form, disp);
            }
            // else an instance is already defined. Return this instance:
            return instance;
        }
    
        public Connection(ConnectionDetails CD, Form form, Display disp) {
            // Init debug log:
            if(debug) {
                // Init debug log:
                InitAppendLog(form, disp);
            }
    
            if ( CD.ValidAddress() )
            {
                connectionDetails = CD;                 // Connection details. (IP, port etc.)
    
                ConnectDisconnectFlag = CD_CONNECT;     // Use Connect routine.
                
                Thread t = new Thread(this);
                t.start();
    
                // Wait until thread ends:
                try {
                    t.join();
                } catch (InterruptedException ie) {
                    // Thread has ended.
                }
            }
            else
            {
                LogEvent("incorrect url, possibly network type not supported");
            }
        }
    
        public boolean ReConnect(ConnectionDetails CD)
        {
            // Use this function after a connected has been disconnected.
            connectionDetails = CD;                 // Connection details. (IP, port etc.)
    
            ConnectDisconnectFlag = CD_CONNECT;          // Use Connect routine.
    
            Thread t = new Thread(this);
            t.start();
    
            // Wait until thread ends:
            try {
                t.join();
            } catch (InterruptedException ie) {
                // Thread has ended.
            }
            return (ConnectionStatus == CONNECTED);
        }
    
        public boolean CloseConnection() {
    
            ConnectDisconnectFlag = CD_DISCONNECT;          // Use Disconnect routine.
    
            Thread t = new Thread(this);
            t.start();
    
            // Wait until thread ends:
            try {
                t.join();
            } catch (InterruptedException ie) {
                // Thread has ended.
            }
            LogEvent("CloseConnection", ConnectionStatus);
            return (ConnectionStatus == DISCONNECTED);
        }
    
        public void run()
        {
            // Attempt Connection:
            if ( ConnectDisconnectFlag == CD_CONNECT)
            {
                if ( (socketConnection == null) || (ConnectionStatus==DISCONNECTED) )
                {
                    if ( connectionDetails.ValidAddress() )
                    {
                        try {
                            String url = SOCKET_ADDRESS + connectionDetails.IpAddr + ":" + connectionDetails.IpPort;
    
                            LogEvent( url );
                            ConnectionStatus = CONNECTING;
                            socketConnection = (SocketConnection)Connector.open(url);
                            socketConnection.setSocketOption(socketConnection.RCVBUF, 1000);
                            socketConnection.setSocketOption(socketConnection.SNDBUF, 1000);
                            socketConnection.setSocketOption(socketConnection.KEEPALIVE, 10000);
                        } catch (IllegalArgumentException iae) {
                            //iae.printStackTrace();
                            LogEvent("Thread Connection (1)>");
                            LogEvent("incorrect url, check and try again");
                            ConnectionStatus = INCONNECT_URL;
                        } catch (ConnectionNotFoundException cnfe) {
                            //cnfe.printStackTrace();
                            LogEvent("Thread Connection (2)>");
                            LogEvent("no such address registered, check and try again");
                            ConnectionStatus = ADDRESS_NOT_FOUND;
                         }   catch (IOException io) {
                            io.printStackTrace();
                            ConnectionStatus = IO_ERROR;
                            LogEvent("Thread Connection (3)>");
                            LogEvent(ConnectionStatus, io.getMessage());
                         } catch (SecurityException se)  {
                            se.printStackTrace();
                            ConnectionStatus = CANNOT_ACCESS_PROTOCOL_HANDLER;
                            LogEvent("Thread Connection (4)>");
                            LogEvent(ConnectionStatus, se.getMessage());
                        } catch (Exception e)  {
                            e.printStackTrace();
                            ConnectionStatus = NO_CONNECT;
                            LogEvent("Thread Connection (5)>");
                            LogEvent(ConnectionStatus, e.getMessage());
                        } finally {
                            if (socketConnection != null) {
                                try {
                                } catch (Exception e) {
                                    LogEvent("Thread Connection (6)>");
                                    LogEvent(ConnectionStatus, e.getMessage());
                                }
                            }
                        }
    
                        if( (socketConnection!=null) && (ConnectionStatus==CONNECTING) )
                        {
                            // Now attempt to open data stream:
                            try {
                                // Open Input and output streams:
                                InStream  = socketConnection.openInputStream();
                                OutStream = socketConnection.openOutputStream();
    
                                ConnectionStatus = CONNECTED;
                                LogEvent(ConnectionStatus);
    
                                } catch (Exception e) {
                                // Catch exception:
                                ConnectionStatus = IO_ERROR;
                                LogEvent("Thread Connection (7)>");
                                LogEvent(ConnectionStatus, e.getMessage());
                            }
                        }
                        else {
                            if(socketConnection != null) {
                                LogEvent("socketConnection = NULL");
                            }
                            LogEvent("ConnectionStatus:"+CONNECTING);
                        }
                    }
                    else {
                        LogEvent("incorrect url, possibly network type not supported");
                    }
                }
                else {
                    LogEvent("socketConnection NOT NULL:" + ConnectionStatus + "\n");
                }
            }
            else if ( ConnectDisconnectFlag == CD_DISCONNECT) {
                if( socketConnection != null ) {
                    try {
                        socketConnection.close();
                        ConnectionStatus = DISCONNECTED;
                    } catch (IOException e) {
                        ConnectionStatus = FAIL_TO_DISCONNECT;
                        LogEvent("Thread Connection (7)>");
                        LogEvent(ConnectionStatus, e.getMessage());
                    }
                    // LogEvent("CloseConnection", ConnectionStatus);
                    //instance.destroyApp(true);
                    destroyApp(true);
                }
            }
            // else should not reach here
        }
    
        public void pauseApp() {
        }
    
        public void destroyApp(boolean unconditional) {
    
        }
    }
    I would be happy if you spot other issues too.

    (Sorry about my coding style it does not comply to java programming style, )
    Last edited by dharmeshkhatri; 2010-04-09 at 13:45.

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Fatal: IO Error:SymbainOS error = -34 : General: System error

    Hello,

    I did not find that where are you closing the socketConnection ,input and the output streams in the quoted code snippets.
    Please check that you are closing the stream and the connection.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Fatal: IO Error:SymbainOS error = -34 : General: System error

    Are you seeing this error on a device, or on the emulator?

    Graham.

  4. #4
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    53

    Re: Fatal: IO Error:SymbainOS error = -34 : General: System error

    Quote Originally Posted by raj_J2ME View Post
    Hello,

    I did not find that where are you closing the socketConnection ,input and the output streams in the quoted code snippets.
    Please check that you are closing the stream and the connection.
    Yes, I am not closing input and output streams. Having made the modifications and I appear to have a successful connection on every attempt.

    I am no longer seeing this message.

    For the record I am running this code on an E71.

    Thanks.

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Fatal: IO Error:SymbainOS error = -34 : General: System error

    I am no longer seeing this message.
    Hey that's cool.

    is that was and fixed your issue?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  6. #6
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    53

    Re: Fatal: IO Error:SymbainOS error = -34 : General: System error

    Quote Originally Posted by raj_J2ME View Post
    Hey that's cool.

    is that was and fixed your issue?
    Is there a way I can tell if a connection is still active following the close command. I amassuming the disconnection does not happen immidaiately in this case.


    Also, do you see any major issues with my code?

    I am not completely sure about the
    Code:
                    destroyApp(true);
    placed in the thread.

  7. #7
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Fatal: IO Error:SymbainOS error = -34 : General: System error

    Quote Originally Posted by dharmeshkhatri View Post

    I am not completely sure about the
    Code:
                    destroyApp(true);
    placed in the thread.

    You can do that however is not the correct way to exit the midlet. You should do this on some events like the command or in case of canvas right/left soft key(depends upon you to decide the key,but commonly the right soft key).
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    53

    Re: Fatal: IO Error:SymbainOS error = -34 : General: System error

    Thanks for your replay,

    Placing destroyApp as part of a soft key is not an option as this class does not accept Commands, it is only for connecting to a host.

    I have removed this command from my code altogether and things seem to work fine. I am able

    Thanks for your reply.

  9. #9
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Fatal: IO Error:SymbainOS error = -34 : General: System error

    Quote Originally Posted by dharmeshkhatri View Post
    Thanks for your replay,
    Placing destroyApp as part of a soft key is not an option as this class does not accept Commands, it is only for connecting to a host.
    I have removed this command from my code altogether and things seem to work fine. I am able
    Thanks for your reply.
    Why this class does not accept commands?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  10. #10
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    53

    Re: Fatal: IO Error:SymbainOS error = -34 : General: System error

    Raj, this is a low level communications driver and as such it does not accept commands.

    However, I have fixed the error by closing the input and output streams.

    Thanks.

Similar Threads

  1. Replies: 7
    Last Post: 2009-03-21, 18:54
  2. i cant build helloworld project
    By akhin in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2008-12-22, 12:38
  3. Error with makesis.exe and creating the .pkg file
    By gramya87 in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2007-10-10, 13:53
  4. Cannot compile SDK's examples for 7650 platform...
    By midletsoft in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2003-08-12, 19:11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •