Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7874577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:49:59+00:00 2026-06-03T02:49:59+00:00

My question is: is there a way to perform a socket OutputStream shutdown or

  • 0

My question is: is there a way to perform a socket OutputStream shutdown or it is not right/fully implemented as it should be by nokia? (J2ME nokia implementation, tested at nokia c6-00 and not closing stream, tested on emulator and works fine)

The main problem is that J2SE server application does not get the end of stream info, the condition read(buffer) == -1 is never true, tries to read from an empty stream and hangs until client is force-killed. This works with a very, very, very ugly workaround on the server side application

        Thread.sleep(10);//wait some time for data else you would get stuck........
        while ((count = dataInputStream.read(buffer)) != -1) {
            byteArrayOutputStream.write(buffer, 0, count);
            if (count != BUFFER_SIZE_1024 || dataInputStream.available() == 0) { //the worlds worst condition ever written... but works
                break;
            }
            Thread.sleep(10);//wait for data input to get some data for dataInputStream.available() to return != 0 if client still sends data else you would not read all data......
        }

but this solution is absolutely not acceptable (i dont know something about nokia java coding, i’m missing something, or is it maybe similar to a some sort of nokia-J2ME coding standard and i should get used to it or change platform)

I can’t close the client socket after sending data because server sends a response to the client after receiving and processing data.

It looks like this: J2ME client -> J2SE server (hangs on read because client does not perform a outputstream shutdown) -> J2ME

I’ve tried to:
close the dataOutputStream on the J2ME client – no effect
setSocketOptions (KEEPALIVE, SNDBUF and others) – no effect or errors

nothing seems to work on the target device

sorry but i’m a bit furious right now after this nonsense fight with little java.

I’have searched for the solution but non seems to work

Client code:

        SocketConnection socketConnection = (SocketConnection) Connector.open("socket://" + ip + ":" + port);
        int count;
        byte[] buffer = new byte[BUFFER_SIZE_1024];
        // client -> server
        DataOutputStream dataOutputStream = new DataOutputStream(socketConnection.openDataOutputStream());
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        while ((count = byteArrayInputStream.read(buffer)) != -1) {
            dataOutputStream.write(buffer, 0, count);
            dataOutputStream.flush();
        }
        dataOutputStream.close();
        byteArrayInputStream.close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:50:00+00:00Added an answer on June 3, 2026 at 2:50 am

    I’ve tried the code with the same effect – on the emulator works like a charm, on the device hangs but i solved my problem as follows:

    On the J2ME client before sending the 1024 byte packet I’m sending its length and its state (IsNext or IsLast) after this on the J2SE server side in a while(true) loop. I’m reading first the length with a readShort, then state with a readByte (I know it’s better to combine it on a one short but I didn’t knew if it will work and if the effort was worth it and now when it works I’m not touching this, besides it is easy to add a new state if necessarily and it works quite fast).

    After this server goes in to a second nested loop [ while (dataInputStream.available() < length) {} – I’ll have to put here a timeout but I’ll worry about that later. Also note that on J2ME dataInputStream.available() always returns a 0 (!) so in the J2ME client read in this place is a for (int i = 0; i < length... loop reading a single byte]

    When the while(dataInputStream.available() ... loop breaks I’m reading a block of data which length I have, and if the state is IsLast I break the while(true) loop. Works perfectly and stable.

    Thanks for the advice and hope this info will help someone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A quick question, is there a way to perform these 3 operations: while(...) {
Question: Is there an easy way (library function) to perform a bitwise AND or
Question Is there a way to define a method only once in C# (in
Question: Is there a way to check if a given font is one of
Silly question - Is there a way to download the iPhone SDK without Xcode
Possible duplicate question: Is there a way to indefinitely pause a thread? In my
The real question: Is there a way to clear certain attributes for all components
I have a very theoretical question: Is there a way to ban the use
Simple question here: is there any way to convert from a jagged array to
My question is: is there a way with a DataContext/Table mapping to implement some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.