Problem with blocking socket.getInput/Output stream :-(

Hi there!
I have a typical client/server application and the problem, that opening the streams leads to clocking behaviour.
This is how I open the streams on the server-side
sock = ssock.accept();
outStream = new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream()));
inStream = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));and this is how I open it on the client-side:
        Socket sock = new Socket(host, port);
        outStream = new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream()));
        //inStream = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));If I leave the inStreeam-Statement uncommented, everything works fine, but as soon I try to catch the input-stream both, the server and the client-side block foreever.
Any ideas whats wrong?
Thank you in advance, lg Clemens

Oh my god, what a brain-dead java-designer played with the thought tha creating a ObjectOutputStream does not lead to a flush() on the underlaying streams ???!!!
Its easy if you know the way to go (same on both sides):
1.) get the Outputstream / create the ObjectOutputStream
2.) flush the ObjectOutputStream (so that the versioning-infp etc is exchanged)
3.) create ObjectInputStream
Step 2 is just extremly stupid in my eyes!
lg Clemens

Similar Messages

  • Problem with the socket and the standard output stream

    Hy, I have a little problem with a socket program. It has the server and the client. The problem is that the client at one point in the program, cannot print messages in the console.
    My program does the next: the server waits connections, when a client connects to it, the server gets outputstream to the socket and writes two strings on it. Meanwhile, the client gets the inputstream to the socket and reads on it with a loop the two strings written by the server . The strings are printed by the client in the console. The problem starts here; once the read strings are printed ,I mean, after the loop, there are other System.out.println in the client but the console doesnt print anything . It curious that only when I comment on the server code the line that says: "br.readLine()" just before the catch, the client prints all the System.out.println after the loop but why?
    Here is the code:
    Server code:
    public class MyServerSocket {
    public MyServerSocket() {
    try{
    ServerSocket server= new ServerSocket(2000);
    System.out.println("servidor iniciado");
    Socket client=server.accept();
    System.out.println("Client connected");
    OutputStream os=client.getOutputStream();
    PrintWriter pw= new PrintWriter(os);
    String cadena1="cadena1";
    String cadena2="cadena2";
    pw.println(cadena1);
    pw.println(cadena2);
    pw.flush();
    InputStream is=client.getInputStream();
    InputStreamReader isr= new InputStreamReader(is);
    BufferedReader br= new BufferedReader(isr);
    br.readLine(); //If a comment this line, the client prints after the loop, all the System.out....
    catch (IOException e) {
    // TODO: handle exception
    public static void main(String[] args) {
    new MyServerSocket
    Client code:
    public class MyClientSocket {
    public MyClientSocket () {
    try{
    Socket client= new Socket("localhost",2000);
    InputStream is=client.getInputStream();
    InputStreamReader isr= new InputStreamReader(is);
    BufferedReader br= new BufferedReader(isr);
    String read;
    while((read=br.readLine())!=null){
    System.out.println(read);
    //These messages are not printed unless I comment the line I talked about in the server code
    System.out.println("leido");
    System.out.println("hola");
    }catch (IOException e) {
    public static void main(String[] args) {
    new MyClientSocket
    }

    You are right but with this program the loop ends. As you see, the first class, the Server, writes to the socket one text file. The second class, the client, reads the text file in his socket written by the server and writes it to a file in his machine.
    NOTE: The loop in the client ends and the server doesnt make any close() socket or shutdownOutput() .
    public class ServidorSocketFicheromio {
         public ServidorSocketFicheromio() {
    try{
         ServerSocket servidor= new ServerSocket(2000);
         System.out.println("servidor iniciado");
         Socket cliente=servidor.accept();
         System.out.println("cliente conectado");
         OutputStream os=cliente.getOutputStream();
         PrintWriter pw= new PrintWriter(os);
         File f = new File("c:\\curso java\\DUDAS.TXT");
         FileReader fr= new FileReader(f);
         BufferedReader br= new BufferedReader(fr);
         String leido;
         while((leido=br.readLine())!=null){
              pw.println(leido);
         pw.flush();
         }catch (IOException e) {
         * @param args
         public static void main(String[] args) {
              new ServidorSocketFicheromio();
    public class ClienteSocketFicheromio {
         public ClienteSocketFicheromio() {
    try{
         Socket cliente= new Socket("localhost",2000);
         File f = new File("G:\\pepe.txt");
         FileWriter fw= new FileWriter(f);
         PrintWriter pw= new PrintWriter(fw);
         InputStream is=cliente.getInputStream();
         InputStreamReader isr= new InputStreamReader(is);
         BufferedReader br= new BufferedReader(isr);
         String leido;
         while((leido=br.readLine())!=null){
              pw.println(leido);
              System.out.println(leido);
              System.out.println("leido");
              System.out.println("hola");
              pw.flush();
         }catch (IOException e) {
         public static void main(String[] args) {
         new ClienteSocketFicheromio();/
    }

  • Problem with SAP Script FAX output

    Hi Friends,
    I have problem with SAP Script Fax output.
    After I issued output using the messge type, the print preview format shows me correct alignments and the right data. But when I go to List display using the menu bar functions from the print preview screen, the list is showing me the right data, but all the alignments at the main window went wrong.
    How do I rectify this problem? I need correct alignments in both form display and list display.

    Hi Sasidhar,
    Have you tried with different fax machine.
    Regards,
    Atish

  • Java Sockets and Output Streams

    Hi All,
    I am beginning sockets programming and I have a problem. If there is a server listening in the background for incoming connections and say for example 4 client programs programs which we shall call client1...client4 connect. How best can I capture the output streams associated with these newly created sockets so that the server can send back isome nformation to say clients1 and client4 only which is not seen by clients 2 and 3. Similarly I would like the server to send some infor to clients 2 and 3 only which is not seen by client1 and client 4.
    Currently I have the server listening part as shown below, but not too sure how to add DISTINCT output streams for 1 and 4 on one hand and 2 and 3 on the other.
    Thanks:
    // bind socket to a port number
    ServerSocket serverSocket = new ServerSocket(portNo);
    // create socket to listen to client connection
    while (true) {
    //listen to an incoming connection
    System.out.println("chatroom server waiting for incoming connections");
    Socket incomingSocket = serverSocket.accept();
    //launch new thread to take care of new connection
    chatRoomThread chatThread = new chatRoomThread(incomingSocket);
    chatThread.start();
    //go back and wait for next connection
    Please help.
    Thanks,
    Bleak

    HouseofHunger wrote:
    yes thats exactly the way I have my in and out streams, in the run method, but that doesn't help me in filtering traffic, in other words I am saying 2 clients, client1 and client4 for example should share a common in and out stream so that they will see eact other's messages... makes sense.....?No, doesn't make sense. That's the wrong design. Each socket should have its own input and output stream (yes, I know, that's been said several times before). If messages going to client1 should also be sent to client4, then whatever writes the messages to client1's output stream must also write them to client4's output stream. Trying to make those two output streams actually be the same output stream is the wrong way to do that. Just have the controller send the messages to whoever is supposed to get them.

  • Is there a way to flush out a socket's output stream without...

    ...having to close it (the stream)?
    I'm trying to implement a keep-alive feature in a simple HTTP Server application. This is a draft of the code I have trouble with:
    ==========
    //'clientSocket' is the socket obtained by the 'serverSocket.accept()' method
    OutputStream out = clientSocket.getOutputStream();
    //'message' is a string to be sent to the client
    InputStream data = new ByteArrayInputStream(message.getBytes());
    byte[] buff = new byte[2048];
    while (true)
    int read = data.read(buff, 0, 2048);
    if (read <= 0)
    break;
    out.write(buff, 0, read);
    out.flush();
    ==========
    If I don't call 'out.close()', the data will not be sent to the client.
    If I call 'out.close()', the data will be sent, but the socket will be closed too, which I don't want to. I need to be able to reuse that socket .
    Is there any way to properly push out the data to the client without having to close the output stream?

    ...having to close it (the stream)?Yes. OutputStream.flush(). But if you're not using any kind of buffered writer/output stream you don't even have to do that.
    If I don't call 'out.close()', the data will not be sent to the client.Untrue. The client will read everything that has been written If you don't close the output stream, the client will never get the EOS indication (e.g. read() returning -1). So if your client is looping until that happens it will loop forever ...
    Your problem at the moment is at the reading end.

  • Problem with photos on dvd output

    Not sure where the kink is in my process, exactly, but maybe someone will have run into this before...
    i'm working with hi-res photos in my FCP sequences mixed with HDV video. I've been using the motion tab to resize and everything looks fine in final cut. When i use compressor to output the m2v file using the standard dvd presets, some of the stills have problems on the resulting file. not all of them look bad and it doesn't seem to be discriminating based on resolution of the original image file. I'm sure there's a good explanation, but the photos that get messed up seem to be random. some look great.
    In the .m2v file played directly off of QT, they sort of just look darker, like perhaps they are interlaced strangely or something and the even or odd rows are black. but when i use that file to burn a dvd in dvd studio pro, the resulting image looks crazy messed up. Anyone know how to wrangle this one? Thanks

    In case someone else runs into this problem, i did some extensive chatting with a final cut guru guy and all we could figure out is that i'm experiencing some sort of bug. that it shouldn't have been doing what it was doing. It started happening after my boss upgraded all of the studio software and quicktime to the latest versions. upon closer inspection, what was happening is that some of my photos were missing fields when exported as a qt, some weird byproduct of interlacing. we tried the settings all sorts of different ways and the problem did, indeed, go away when i changed the sequence to progressive, but i didn't want to sacrifice resolution of the rest of the footage just because of the problem with the few photos that were janky, so i found two workarounds that fixed the problem...
    1) using the de-interlace effect on just the photos that were giving me problems. it lowered the resolution, but not enough to make a difference and it looked good.
    2) using the motion blur effect. This filled in the missing fields and i did it at such an unnoticeable setting that it might have even looked better than the pictures i de-interlaced.
    If this jogs someone's brain as to what the actual problem was in the first place and you think it's not just a bug in the system, then i'd be interested to hear how to avoid the problem in the future.

  • Premiere Elements cause problems with Windows Media Center while streaming to TV.

    I was having the following problem:
    The audio from the streaming process of a recorded TV show on my HP computer to the remote receivers, a Sony Blu-ray player and/or a Sony Streaming Player, results in the loss of audio signal at exactly 30 seconds from the beginning on either devices. The video continues on as normal.
    A user on the Windows 7 forum had the following possible cause and solution.  His response was as follows:
    I "solved" my issue, at least partially. Turns out for me a codec installed by Adobe Premiere Elements for audio (Main Concept) was causing mfpmp.exe to fail (you should see it getting an appcrash in the event log two or three times as soon as you start playing the media remotely.) This program is used by microsoft for DRM. I went through and one by one remained the various attached (non-microsoft) modules until i found the one that caused the appcrash. I haven't fully figured out if Elements is now negatively effected, but that's for a different forum.
    I tried the quick fix by un-installing Adobe Premiere Elements.  The uninstall solved my problem with Windows Media Center, but I want to re-install the software but I do not want to recreate the problem with Windows Media Center.
    Is there another solution for this problem?

    I reinstalled Adobe Premiere Elements 10 and the above mention problem reoccured.  With a little detective work I was able to determine that the file causing my problem was "mc_dec_dd_ds.ax".  I am not sure what this does to Adobe Premiere Elements 10 since I removed (renamed) the offending file.  A strange side affect, renaming the file did cause an increase volume. Strange.  

  • Problem with Headphone socket

    There is some problem with the headphone socket of my nokia lumai 920. One headset is not working. But the headset is working fine in other phones.  
    What is the possible solution for this?

    Sachin1028 wrote:
    Hi,
    Restatrting the phone fixed the issue. Dont know what happened actually or if the problem will occur again or not. 
    Good to hear that. Reminds me to start from the basics first 

  • Problem with blocked native processes

    My application relies heavily on native processes so that I am trying to implement fallback strategies if a native process doesn't work as expected.
    While creating test scenarios I had a problem with handling errors caused directly by the start() method of the NativeProcess class. It throws errors if the target process can’t be accessed or is corrupted. For example if you take an exe file in Windows that works correctly and modify it in a hex editor to corrupt it the following error is thrown:
    Error: Error #3219: The NativeProcess could not be started. '%1 is not a valid Win32 application.'
          at flash.desktop::NativeProcess/internalStart()
          at flash.desktop::NativeProcess/start()
    If I try to put a try-catch block around the process.start() call something unexpected happens:
    The error is cought correctly, but another error is thrown instantly:
    Error: Error #1503: A script failed to exit after 30 seconds and was terminated.
          at mx.managers.layoutClasses::PriorityQueue/removeSmallest()[E:\dev\4.x\frameworks\projects\ framework\src\mx\managers\layoutClasses\PriorityQueue.as:238]
          at mx.managers::LayoutManager/validateProperties()[E:\dev\4.x\frameworks\projects\framework\ src\mx\managers\LayoutManager.as:567]
          at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framewo rk\src\mx\managers\LayoutManager.as:730]
          at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects \framework\src\mx\managers\LayoutManager.as:1072]
    The problem with this error is that I got no idea how to catch or prevent it. Depending on what I do in the catch block there is another error. For example if I try to log the error I get (but sometimes not as instantly as above):
    Error: Error #1503: A script failed to exit after 30 seconds and was terminated.
          at mx.logging::Log$/getLogger()[E:\dev\4.x\frameworks\projects\framework\src\mx\logging\Log. as:360]
    Strange is that the error is fired instantly sometimes not after 30 seconds.
    How can I fix this?

    In the first case I used a loader to load an error image. In the second case I tried something like:
    var logger:ILogger = Log.getLogger("Test");
    logger.error("NativeProcessError");
    I don't have the exact code at the moment, because I'm not on that computer.

  • Socket input / output stream

    Does anyone know if the input / output streams returned by getInputStream() / getOutputStream() in java.net.Socket are buffered by default?

    y they are buffered, but to use the buffer, you have to use available() and read(byte[] buf ...

  • RMAN problem with block corruption

    Hi
    I have problem with the block corruption in one of the database .
    here is the error message .
    ora-01578:oracle data block corrupted (file# 10,block # 55309) ora-01110: data file 10:
    '/db/gist1/data/gist1_gis_nologging_01.dbf' ora-26040: data block was loaded using the NOLOGGING option .
    gisq SQL> select * from v$database_block_corruption;
    FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
    10 11 126 3754364971 LOGICAL
    RMAN> blockrecover datafile 10 block 11;
    Starting blockrecover at 14/DEC/2012 16:25:48
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of blockrecover command at 12/14/2012 16:25:48
    RMAN-05009: Block Media Recovery requires Enterprise Edition
    Could some one help me in providing solution for this . we we have standard addition only .
    Thanks in advance ...

    It appears that there was a NOLOGGING operation on an object that resides in '/db/gist1/data/gist1_gis_nologging_01.dbf' .
    NOLOGGING operations, as the name suggests, do generate limited redo log, which makes the objects affected by them non-recoverable.
    RMAN Blockrecover, as far as I understand, uses full and archivelog backup to perform the block recovery. Since the archivelog backup does not store any changes related to the NOLOGGING operation, then Blockrecover would not be able to help you even if you were licensed.
    You can try to restore the object as of the most recent full backup…
    Iordan Iotzov
    http://iiotzov.wordpress.com/

  • Strange problem with SSL Sockets using more than 10 Clients

    Hi
    I�m using Jsse ( JDK 1.4.2_06 ). I have coded a Client/Server Applikation acting over SSLSockets or over unsecured Sockets. If I use unsecured Sockets everthing works fine, but if I use SSLSockets for the Connection and about 20 Clients, the Clients often can�t connect to the Server and the following Exception was thrown:
    java.net.ConnectException: Connection refused: connect
    Could it be that there is some strange problem with SSLServerSockets relating to this phenomenon?
    If I use only a few Clients the Exception occurs never or only sometimes.
    Has anyboby an idea what is happaning there?
    Regards Chrisli

    Hi
    From the description of your scenario, you have coded your own server side of the application. I would advise that you consider moving your application to run under Tomcat framework and test if you still get the same exception.

  • UrlParam problem with Captivate 7 Flash output

    Has anyone else had trouble with urlParam in Flash output for Captivate 7?  I can't grab the first variable.  It works fine with HTML5 output.  Here is the script:
    var objCP
    if (typeof window.cp==='undefined') {
    var objCp=document.getElementById('Captivate');
    if(objCp && objCp.cpEIGetValue){
      isHTML5 = false;
    else {
    if(cp.vm && cp.vm.getVariableValue){
      isHTML5 = true;
    var oURL = window.location.href.toString();
    var URLparams = new Array();
    if (oURL.indexOf("?") > 0){
    //var split up by
    var sValues = oURL.split("?");
    var aValues = sValues[1].split("&");
    for (i=0;i<aValues.length;i++){
      //split by = sign
    var sEquals = aValues[i].split("=");
    URLparams[sEquals[0]]=sEquals[1];
    setValue('checksum', URLparams);
    setValue('csid', URLparams);
    setValue('id', URLparams);
    function setValue(id, URLParams){
    if(isHTML5){
      if(typeof window[id] === 'undefined'){
       cp.vm.setVariableValue(id, URLparams[id]);
      } else {
       window[id] =URLparams[id];
      } else {
      objCP.cpEISetValue(id, URLparams[id]);
    function getURLvalue(id, myarray){
    for(var i=0; i<myarray.length;i++){
      if(myarray[i][0] == id) return myarray[i][1];
    return false;

    The script is on the entry of the first slide to set the variables as the slide show begins.  I did publish to both swf and html5.  I'm using the index.html page for the html5 and the other htm page that contains the flash object. I have a php script that detects mobile devices to determine which content is displayed using iframes.  I'm not sure what the multiscreen.html page is... ok I just read about the multiscreen and it looks like that page doesn't detect all devices correctly so I'm better off with the php script that I'm using.  I'm adding the variable string to each url on the index page and also the htm page for embedded flash content.

  • Problem with iMac mini DVI output to TV via VGA

    Hi
    I've searched these forums and Googled but haven't found the answer to this problem!
    Basically, I'm trying and so far failing to connect an iMac that I bought in mid 2007 (v 5.1, OS X 10.6.5) to a new HD TV (Sony KDL-32EX403). I'm using a Mini DIV to VGA adaptor from the iMac with a VGA cable that goes into the 'PC' input round the back of the TV. When I try and select the 'PC' function from the inputs menu on the TV, the icon is greyed out.
    No matter what I try - turning mirroring on and off, changing resolution, unplugging, restarting - it makes no difference. Weirdly the display menu does acknowledge that the Mac is connected to a Sony TV and gives a list of resolutions to choose from.
    However... when I tried connecting my PC notebook using the straight VGA cable (output on the PC, input to the TV) the image appears fine. So I took the cable out of the PC, screwed on the VGA-DVI adaptor and plugged it back into the Mac and it worked! However when I switched back to TV mode I could not switch back to PC input, the icon was once again greyed out.
    Sigh...
    I see no reason why this doesn't work without this awkward workaround so if anyone can help or has had a similar problem please shout!
    Thanks
    Message was edited by: philbrownuk

    I have my Macbook (early 2008) hooked up to a 19-inch TV I use as a second desktop. You won't find any cords that go straight from mini-DVI to HMDI, and even if you do I wouldn't recommend them. You'll have to get an adapter cable that goes from mini-DVI to DVI and then get a DVI to HDMI cable. I got the Apple-made adapter (about $20) even though it's more expensive because apparently third party ones can have problems. You can get a DVI to HDMI cable anywhere, they can run expensive but I got one off Amazon for less than $10.
    That connection is video only so yes, you'd need a different connection for sound. As to how you hook the sound up, it depends on what you want to use for sound. If you want the sound to come from the TV speakers then you'd have to use a different cord than if you wanted to hook it up to a sound system. If you let me know I can explain what you'd need to do for that. Hope this helped

  • Problem with Non-English Fields Output to PDF by JASPER in JDev10.1.3

    I am using jsprx files(designed in i-report) to generate pdf reports out of an oracle database.
    The non-English fields are shown correctly when I output the report into an HTML or when I view it with JasperView.
    If I try making PDF files (JasperExportManager.exportReportToPdfFile) the static fields containing e.g.Arabic/Chineese characters won't be displayed and dynamic fields from the database with non-English contents will be shown as ??? or null.
    I received some suggestions about using PARAMETERS to feed the report instead of FIELDS, which I think can not be helpful in this case and in general.
    I think this should be a common problem. These are the components I am using:
    itext-1.4.7. jar
    commons-digester- 1.7.zip
    jasperreports- 1.2.8.jar
    Any comment or help is appreciated.
    Thanks
    Farbod

    I am using jsprx files(designed in i-report) to generate pdf reports out of an oracle database.
    The non-English fields are shown correctly when I output the report into an HTML or when I view it with JasperView.
    If I try making PDF files (JasperExportManager.exportReportToPdfFile) the static fields containing e.g.Arabic/Chineese characters won't be displayed and dynamic fields from the database with non-English contents will be shown as ??? or null.
    I received some suggestions about using PARAMETERS to feed the report instead of FIELDS, which I think can not be helpful in this case and in general.
    I think this should be a common problem. These are the components I am using:
    itext-1.4.7. jar
    commons-digester- 1.7.zip
    jasperreports- 1.2.8.jar
    Any comment or help is appreciated.
    Thanks
    Farbod

Maybe you are looking for