How can I read from the InputStream when I use StreamConnectionNotifier

I want to make a program that will listen on port 100 and exchange with PC message.

And the program uses wifi to connect with the PC.

I have StreamConnectionNotifier choice and I can receive request for socket of PC, but when I open imputStream, Exception throw.

My code:

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

Import javax.microedition.io.Connector;
Import javax.microedition.io.StreamConnection;
Import javax.microedition.io.StreamConnectionNotifier;

SerializableAttribute public class ServerThread extends Thread {}
constants
private public static final String URL = ""http://:100;interface=wifi;deviceside=false "; "
fields
private StreamConnectionNotifier _notify;
private InputStream _in;
private OutputStream _out;
private StreamConnection stream = null;
private HelloWorld _app;
   
Private boolean isStop = false;
 
public ServerThread() {}
  
}
 
{} public void setApp (HelloWorld app)
_APP = app;
}
 
public void run() {}
try {}
{while(!isStop)}
{Synchronized (this)}
_notify = Connector.open (URL) (StreamConnectionNotifier);
}
Stream = _notify.acceptAndOpen ();
_in = stream.openDataInputStream ();  //<-- i="" think="" this="" line throw="" excepiton,="" excepiotn="" 's="" message="" is:request line="" is="">
_out = stream.openDataOutputStream ();
extract the data from the input stream
StringBuffer sb = new StringBuffer();
Reference int = - 1;
{While (-1! = (reference = {_in.read ()))}
Reference of the SB. Append ((Char));
}
    
_APP.updateText (SB. ToString());
    
StringBuffer res = new StringBuffer();
Res. Append ("HTTP/1.0 200 OK \r\n");
Res. Append ("Content-type: text/html \r\n");
Res. Append ("Content-Length: 1 \r\n");
Res. Append ("1");
_out. Write (res. ToString(). GetBytes());
    
_in. Close();
_out. Close();
_notify. Close();
}
} catch (IOException e) {}
probably the stream has been closed.
System.Err.println (try ());
_APP.updateText (try ());
} {Finally
try {}
If (stream! = null) {}
Stream.Close ();
}
} catch (Exception ex) {}
}
try {}
If (_notify! = null) {}
_notify. Close();
}
} catch (Exception ex) {}
}
}
}
 
{} public void stop()
isStop = true;
try {}
If (stream! = null) {}
Stream.Close ();
}
} catch (Exception ex) {}
}
try {}
If (_notify! = null) {}
_notify. Close();
}
} catch (Exception ex) {}
}
}

}

When I use IE application this port the program can block reading of inputStream.

What's wrong? Please help me.

What could happen is the following (Please check if this is the case however). Your code side device receives an incoming connection, but is then stuck on waiting for InputStream.read return anything. This translates your code aside PC it also blocks its BufferedReader.readLine, because the device-side code is not send anything (yet). So, you have a classic network impasse. If it is exactly what is happening, then you can try to fix the problem in several ways.

1. change the code aside device to read byte-by-byte (int InputStream.read () instead of void InputStream.read (byte [],...)). It might help because on a few BlackBerrys the TCP stack returns the data received so that the stream is closed by a peer until you start viewing byte-by-byte.

AND/OR

2. change the PC-side code to close the output stream before reading the input stream (that's how works HTTP/1.0, for example). It might help because on a few BlackBerrys the TCP stack does not return data received until the stream is closed by a peer.

Tags: BlackBerry Developers

Similar Questions

  • After you create a new playlist in iTunes, every song has the cover of the album and no box on the left side. How can I remove from the work and recover the box? TIA

    After you create a new playlist in iTunes, every song has the cover of the album and no box on the left side. How can I remove from the work and recover the box? TIA

    You can change the appearance of a selection by clicking on "reading list" in the upper right of the iTunes window. The desired view is probably "tracks"

  • Satellite 5205-s705: How can I boot from the CD/DVD drive

    I can't run Setup from my cd/dvd rom, there is no such option in the BIOS Setup. How can I boot from the cD or DVD?
    Please, help me!

    Hello

    You are not able to boot from the CD/DVD drive?
    If you are unable to change the boot order in the BIOS, I would advise you by pressing the F12 key immediately after starting the laptop.
    A start menu should appear, then you should be able to choose the reader of CD/DVD (ODD).

    You can also try clicking on the C instead of the F12 button. The C button the STRANGE start.

    Check this back and forth!

    Good luck

  • How can I boot from the Windows 7 Installation CD so that I can reformat the hard drive before reinstalling Windows 7?

    How can I boot from the Windows 7 Installation CD so that I can reformat the hard drive before reinstalling Windows 7?  I have already reinstalled Windows 7 from the CD, but that has not solved my problems.  When I put the factory CD in my CD player, it won't always boot from the CD.  When I put my Windows 7 Ultimate CD in the CD drive, it doesn't always start from the CD.         I realize that the reformatting is not always necessary, but I caught a few viruses (despite anti-virus running) and I need to start with a clean hard drive.

    On Friday, January 9, 2015 14:30:32 + 0000, BlueKodak wrote:

    How can I boot from the Windows 7 Installation CD so that I can reformat the hard drive before reinstalling Windows 7?  I have already reinstalled Windows 7 from the CD, but that has not solved my problems.  When I put the factory CD in my CD player, it won't always boot from the CD.  When I put my Windows 7 Ultimate CD in the CD drive, it doesn't always start from the CD.

    You must go into the BIOS and change the boot on CD order
    first push.

    How to get into your BIOS? It is not dependent on Windows, but on what he
    motherboard/BIOS card that you have. In fact, you need access to the
    BIOS before Windows begins to start. A common method is to press
    the key delete when you turn on first, but this is not necessarily true
    for your computer. Watch the display carefully when you start first;
    There is often a message here to tell you what to do. If this is not the case, check
    your system documentation or check with your provider.

  • How can I unsubscribe from the annual service? for my funds do not charge?

    I only use the software never and want to cancel your subscription. How can I unsubscribe from the annual service? for my funds was not charged?

    Contact adobe during the time pst support by clicking here and, when available, click on "still need help," http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • How can I stop and then resume when you use the magnetic Lasso tool?

    CS4 on Mac. I have some fairly complicated selections to make and the magnetic lasso tool seems a good choice. However: How can I stop and then resume when in use? For example, I would like to zoom, start by dragging along the edge, then stop, move the image to a different area of it is in the middle of my screen, then pick up again where I left.

    Hi MarieMeyer,

    You can press the SPACEBAR shortcut to activate the hand tool temporarily once you are finished with the selection on a part of the image.

    Then, move the image with the key space key and let it continue with the selection by using the magnetic lasso tool.

    You can use the SHIFT key to add to the selection by using the magnetic lasso tool.

    Kind regards

    Claes

  • "nothing can be sent from the Office" when you try to print

    Original title: the problem of office printing

    Windows 8: I can't print anything.  He said: "nothing can be sent from the office.  Two hours ago, it was printing.  It happened once before and I accidentally found something clicked, active summer and it worked again.  They make it almost impossible to find! I can't find this time and so cannot print.  Where can I activate "the workstation sending" on my printer please.  I hate Windows 8!  Thank you.

    Hello

    -You use the devices option in the charms bar to select the printer and then print whatever it is?

    The message 'Nothing can be sent from the Office' means simply that you must do this from the 'Start' screen or in an app Store instead of from the "desktop". If you get "Has nothing to send right now" the splash screen or the app Store, then this means that you don't have any external device (ex: projector, printer, etc.) connected to send anything to, or the application does not support.

    Here is a work around that you can try.

    If you try to print from a program like MS word or notepad, and then press the CTRL key and the P key to access the printer Options. You will find the printer that is installed on the computer.

    Navigate through the steps of troubleshooting provided in http://answers.microsoft.com/en-us/windows/forum/windows_8-hardware/devices-nothing-can-be-sent-from-this-desktop/532f81de-435d-4121-a9e3-2ed57a1bf31a

    This is a wonderful tutorial on how to get used to Windows 8. Hope that this will make it easier to use Windows 8. http://Windows.Microsoft.com/en-in/Windows-8/tutorial

    If you have any questions, please let us know.

  • I can not package for the project when I used the blackberry resource files

    I can't package the project when I used the blackberry resource files.

    Packaging HelloWorl project
    C:\eclipse\plugins\net.rim.ejde.componentpack5.0.0_5.0.0.25\components\bin\rapc.exe-quiet codename=deliverables\Standard\5.0.0\HelloWorl deliverables\Standard\5.0.0\HelloWorl.rapc-sourceroot=C:\workspace\HelloWorl\.locale_interfaces; C:\workspace\HelloWorl\src; C:\workspace\HelloWorl\res-import=C:\eclipse\plugins\net.rim.ejde.componentpack5.0.0_5.0.0.25\components\lib\net_rim_api.jar C:\workspace\HelloWorl\bin
    Cannot open the C:\workspace\HelloWorl\bin/com.helloresL.crb/ dir
    Error! : error: auditor failed: C:\eclipse\plugins\net.rim.ejde.componentpack5.0.0_5.0.0.25\components\bin\preverify.exe d C:\DOCUME...
    Packaging project HelloWorl failed (taken in 0,219 seconds)

    I have fixed my problems, I was using a unicode language in windows, so I changed the language for non-unicode format.

  • How can I import from Outlook 2007 when the option is grayed out?

    I'm moving from Outlook 2007 to Thunderbird. All is well until now, but I need to import my old mails from Outlook. When I go to tools > import > Mail I get options for Eudora, Outlook, and Outlook Express. Eudora and Outlook options are grayed out. The option for Outlook Express is available, but who isn't even an option for me, since I am on Windows 7.

    I've read a few articles, and they point out that you must always have Outlook installed and configured as the default e-mail client. I made sure Outlook is set as the default mail client, but the import option is still grayed out. I tried restarting both Outlook and Thunderbird. I also tried the import with Outlook open and closed.

    Any help would be appreciated.

    You must Version31 or an earlier version. Something happened along the way with exit 38 and transformed into an accident. It is therefore turned off until it gets.

    Which language version would you need?

  • A40-201: How can I boot from the CD?

    Hello

    Can someone tell me how I can configure this laptop to boot from the CD?
    I try to go into the bios, but this option is not available... I'm trying to press F12... but also unsuccefull...

    Tanks in advance...

    Hello

    -Put the CD in the drive.
    -Stop the laptop.
    -Then turn on the laptop and immediately the key C.
    Now, the laptop should boot from the CD.

  • I changed my "opinion" in full screen... How can I change from the Bar Menu with "view" is no longer available in "full screen"? I tried Esc, but it does not work...

    I used tab DISPLAY in the top left to change my mind in 'full screen '.
    Now I can't access the VIEW tab to restore. How can I change back so that this Menu will appear at the top of my screen?

    A few choices:

    1. F11 toggle full screen
    2. Move mouse in the upper part of the screen to menu bars, if show you them
    3. 'Alt + V' - to bring up the View Menu

    More information:

  • How can I print from the samsung galaxy tab 10.1?

    I have a samsung galaxy tab 10.1 and I recently bought a printer Photosmart HP 6510. Both are in the wireless network but I can't print from my tablet. Anyone have any suggestions?

    Hello

    You can print using HP ePrint home & Biz, from the Google game store available:

    http://support.HP.com/us-en/document/c02775166

    Kind regards

    Shlomi

  • How can I disconnect from the internet but to maintain my connection to the local network in Windows 7?

    I need to disconnect internet to my PC Windows 7 while maintaining my LAN network. Can anyone help?

    Hello

    If you want to disconnect Internet on the Windows 7 computer, then you can follow the steps mentioned below. These steps would help you to disconnect from the wired connection, while the connection is still active.

    (a) click Start.

    (b) type network and sharing Center in the start search bar and press ENTER.

    (c) in the left pane, click on change adapter settings

    (d) it would be to open a window with the connection to the wired LAN.

    (e) now, right click on the wired LAN connection icon and select Disable. (Provide the password if necessary).

    (f) it would disconnect the computer from Windows 7 to connect to the local network.

  • How can reinstall Setup from the control center of intel

    I can't install INTEL's CONTROL CENTER in my windows 7 home basic laptop... it asks windows xp... Give me a solution...?

    Hi Chacko15,

    1. What is the exact error message you are getting?

    Thanks for posting in the Microsoft Community.

    I understand that you are facing problems while installing the Intel control center software.

    1. What is the brand and model of the computer?

    It seems that Intel control center is compatible with Windows 7

    See the link.

    http://www.Microsoft.com/Windows/compatibility/Windows-7/en-us/details.aspx?type=software&p=Intel%20Control%20Center&v=Intel&UID=1&l=en&pf=0&pi=2&s=Intel%20CONTROLE%20Centre&OS=32-bit

    Please try to download the software for Windows 7 from the link below.

    http://Downloadcenter.Intel.com/default.aspx?lang=eng

  • How to remove URLs from the browser when browser Acrobat PDF document conversion?

    Hello

    I am trying to print a page of web browser. The browser page is converted to a PDF file, and then it must be printed. In doing so, link the web from the browser is automatically attached to the PDF document. But I don't want to have the web link. How do I remove it?. I use Adobe Acrobat 9.

    Thanks in advance.

    Kirup.

    It is a feature of your browser, not Acrobat printing options. You need to find the printing options in your browser. In Seamonkey, it is under Page Setup.

Maybe you are looking for