java - Broken Pipe exception when trying to write a file -


I am trying to write a very simple application that uploads a video to a server on HTTP with an upload request Will do Here's how my code looks:

  socket = new socket (); Socket.connect (new InetSocketAddress (ticket.getHost (), 80)); OutputStream = socket.getOutputStream (); / / Outputstream. Start creating a written request ("Put" + Ticket GetendPoint () + "HTTP / 1.1 \ r \ n" + "Host:" + ticket.getHost () + "\ r \ n" + " Content-Length: "+ getStreamFile (). Length () +" \ r \ n "+" Content-Type: Video / MP3 \ r \ n \ r \ n "). GetBytes ()); // Now, write some binary data file in InputStream = new FileInputStream (getStreamFile ()); Inputstream = new BufferedInputStream (fileInputStream); Byte [] fileBytes = new byte [1024]; Int BitesRad = 0; Int totalBytesRead = 0; While ((BytesRed = inputstream.red (file bits) gt; 0) {outputstream.write (fileBytes, 0, bytes read); TotalBytesRead + BitesRed; Notify notifications (progress) (total) total bytesread / (double) getStreamFile (). Length ()); }   

Very simple, is not it? Until I see this error after about two ends:

  java.net.SocketException: java.net.SocketOutputStream.socketWrite0 (the original method) ~ [na: 1.6.0_23] Broken pipe Java.net.SocketOutputStream.socketWrite (SocketOutputStream.java:109) ~ [na: 1.6.0_23] at java.net.SocketOutputStream.write (SocketOutputStream.java:141) ~ [na: 1.6.0_23]   

What am I doing wrong here?

Do not do this stuff by hand, use the HttpURL connection for it, this is what it is for . Create the URL, get the HTTPPLL connection from it, set the request method to "fold", set content-type, do not set content length, get output stream, and start typing < / P>

Comments