Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: send image file from java to php broken pipe exception occured

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default send image file from java to php broken pipe exception occured

    FileInputStream fis = new FileInputStream("/Users/ashida/test/Cross.jpg");
    byte[] buffer = new byte[fis.available()];
    fis.read(buffer);
    ObjectOutputStream oos = new ObjectOutputStream(client.getOutputStream()) ;
    oos.write(buffer);
    oos.close();
    error is occured .. please help me to find out this..


    java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutp utStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStre am.java:136)
    at java.io.ObjectOutputStream$BlockDataOutputStream.w riteBlockHeader(ObjectOutputStream.java:1864)
    at java.io.ObjectOutputStream$BlockDataOutputStream.w rite(ObjectOutputStream.java:1822)
    at java.io.ObjectOutputStream.write(ObjectOutputStrea m.java:689)
    at clientserverapplication.ImageServer.main(ImageServ er.java:47)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: send image file from java to php broken pipe exception occured

    Does the code reading know what a java object is?

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: send image file from java to php broken pipe exception occured

    i have debug this application oos.write(buffer); this line makes the error i am using socket programming from connecting java and php.. this program send the image to php.


    full code


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package clientserverapplication;


    import java.net.*;
    import java.io.*;

    public class ImageServer {
    public static void main(String[] args) {

    int port = 2035;
    ServerSocket listenSock = null; //the listening server socket
    Socket client = null; //the socket that will actually be used for communication

    try {

    listenSock = new ServerSocket(port);
    System.out.println("Server setup and waiting for client connection ...");

    while (true) {

    client = listenSock.accept();
    System.out.println("Client connection accepted.");

    BufferedReader br =
    new BufferedReader(new InputStreamReader(client.getInputStream()));
    BufferedWriter bw =
    new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
    String line = "";
    while ((line = br.readLine()) != null) {

    if(line.equals("php"))
    {
    FileInputStream fis = new FileInputStream("/Users/ashida/test/Cross.jpg");
    byte[] buffer = new byte[fis.available()];
    // fis.read(buffer);
    int count = 0;
    ObjectOutputStream oos = new ObjectOutputStream(client.getOutputStream()) ;
    //while ((count = fis.read(buffer)) >= 0) {
    oos.write(buffer);
    oos.close();

    //}
    bw.flush();

    }
    }
    bw.close();
    br.close();
    client.close();
    }
    } catch (IOException ex) {
    ex.printStackTrace();
    //System.out.println("Did not accept connection: " + ex);
    }
    }
    }

Similar Threads

  1. Error occured during attachment of file using java.
    By kaliyaodi in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 4th, 2011, 05:30 PM
  2. send image (logo) and text & barcode to the Zebra Printer
    By ehsanlinux in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 11th, 2011, 05:41 AM
  3. Broken JPanel?
    By psu in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 22nd, 2011, 11:11 AM
  4. Please solve my error occured java.lang.NullPointerExceptio
    By Viruthagiri in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: March 24th, 2010, 08:29 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM