Click here to Skip to main content
15,503,143 members
Home / Discussions / Java
   

Java

 
GeneralRe: No value specified for parameter 2 Pin
Richard Deeming3-Jul-17 8:06
mveRichard Deeming3-Jul-17 8:06 
GeneralRe: No value specified for parameter 2 Pin
karengsh3-Jul-17 17:33
karengsh3-Jul-17 17:33 
GeneralRe: No value specified for parameter 2 Pin
Richard MacCutchan3-Jul-17 22:20
mveRichard MacCutchan3-Jul-17 22:20 
GeneralRe: No value specified for parameter 2 Pin
karengsh4-Jul-17 6:51
karengsh4-Jul-17 6:51 
GeneralRe: No value specified for parameter 2 Pin
LynxEffect9-Aug-17 10:56
LynxEffect9-Aug-17 10:56 
Questionusing firefox progmatically with java Pin
Member 132904603-Jul-17 3:45
Member 132904603-Jul-17 3:45 
AnswerRe: using firefox progmatically with java Pin
Richard MacCutchan3-Jul-17 4:22
mveRichard MacCutchan3-Jul-17 4:22 
Questionjava.net.SocketException: Software caused connection abort: socket write error Pin
Django_Untaken1-Jul-17 10:57
Django_Untaken1-Jul-17 10:57 
Hello there. I am trying to send images (byte[] data) to web browser using java. I am doing this in a while(true) loop. My ClientThread sends one image only. After that, it starts producing this exception. Here is what I have tried so far
Overview

1- MainThread starts ServerThread
2- ServerThread start ClientThread
3- ClientThread has a loop. In this loop, I read next image and pass it to MovieWriter (which writes it to DataOutputStream of clientSocket) with a delay of 50ms



class ClientThread extends Thread
{
  @Overrie
  public void run()
  {
    OutputStream outStream = clientSocket.getOutputStream(); // clientSocket = class variable
    DataOutputStream dataOutStream = new DataOutputStream(outStream);

    MovieWriter mv = new MovieWriter(dataOutStream);
    mv.WriterHttpHeader();
    while(true)
    {
      Thread.sleep(50);
      ByteArrayOutputStream image = ReadImage.GetNext(); // 'ReadImage' is static class which returns the next image
      mv.WriteNextImage(image.toByteArray());
    }
  }  
}

class MovieWriter
{
  public MovieWriter(DataOutputStream)
  {
    // set class variable
  }

  public void WriterHttpHeader()
  {
    String header = "HTTP/1.1 200 OK \r\n Content-Type: multipart/x-mixed-replace; boundary=--boundary";
    dataOutputStream.write(GetBytes(header)); // dataOutputStream = class variable; GetBytes() return bytes of header
  }

  public void WriteNextImage(byte[] data)
  {
    try
    {
      String response = "Content-Type: image/jpg \r\n" + "Content-Length: " + String.ValueOf(data.length);
      dataOutputStream.write(GetBytes(response)); // first write response header
      dataOutputStream.write(data);      // then write image data
    } catch(Exception ex) {
      ex.printStackTrace();
    }
  }
  
}


Again, when the while loop in ClientThread runs, MovieWriter sends one image only. After that, it raises the said exception. What am I doing wrong? Thanks for anything you share Smile | :)

NOTE: I cut this code short for better understanding. If you need more code, I can provide
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Richard MacCutchan1-Jul-17 21:53
mveRichard MacCutchan1-Jul-17 21:53 
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Django_Untaken2-Jul-17 0:39
Django_Untaken2-Jul-17 0:39 
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Richard MacCutchan2-Jul-17 2:37
mveRichard MacCutchan2-Jul-17 2:37 
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Django_Untaken2-Jul-17 8:33
Django_Untaken2-Jul-17 8:33 
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Richard MacCutchan3-Jul-17 4:23
mveRichard MacCutchan3-Jul-17 4:23 
QuestionInput:12-4-78==OUTPUT:12041978 //Input:9-4-78==OUTPUT:09041978 Pin
Member 1327696824-Jun-17 8:52
Member 1327696824-Jun-17 8:52 
AnswerRe: Input:12-4-78==OUTPUT:12041978 //Input:9-4-78==OUTPUT:09041978 Pin
Michael_Davies24-Jun-17 9:42
Michael_Davies24-Jun-17 9:42 
SuggestionRe: Input:12-4-78==OUTPUT:12041978 //Input:9-4-78==OUTPUT:09041978 Pin
Richard Deeming26-Jun-17 1:46
mveRichard Deeming26-Jun-17 1:46 
AnswerRe: Input:12-4-78==OUTPUT:12041978 //Input:9-4-78==OUTPUT:09041978 Pin
jschell28-Jun-17 7:16
jschell28-Jun-17 7:16 
QuestionHow should I go about getting the generated key from one DAOImpl to another DAOImpl ? Pin
karengsh18-Jun-17 6:30
karengsh18-Jun-17 6:30 
AnswerRe: How should I go about getting the generated key from one DAOImpl to another DAOImpl ? Pin
Mike.F.Hewitt18-Jun-17 12:14
Mike.F.Hewitt18-Jun-17 12:14 
GeneralRe: How should I go about getting the generated key from one DAOImpl to another DAOImpl ? Pin
karengsh23-Jun-17 22:34
karengsh23-Jun-17 22:34 
QuestionJava Pin
Member 1326557218-Jun-17 2:38
Member 1326557218-Jun-17 2:38 
JokeRe: Java Pin
Richard MacCutchan18-Jun-17 23:53
mveRichard MacCutchan18-Jun-17 23:53 
JokeRe: Java Pin
John C Rayan19-Jun-17 5:16
professionalJohn C Rayan19-Jun-17 5:16 
GeneralRe: Java Pin
Richard MacCutchan19-Jun-17 5:23
mveRichard MacCutchan19-Jun-17 5:23 
QuestionWhere to place connection using servlet Pin
digibat13-Jun-17 18:18
digibat13-Jun-17 18:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.