Hi ,
I am using webcam-capture api in order to connect with webcam.
How i can send the webcam from sockets live streaming from server to client.
Printable View
Hi ,
I am using webcam-capture api in order to connect with webcam.
How i can send the webcam from sockets live streaming from server to client.
anyone please reply provide me reference , tutorials etc
What code do you have now? Can you write and read data over a socket?
...and commenting in the chat box that this forum sucks is not doing you any favors.
Yes im writing and reading from sockets.
Im using webcam-capture API for it.
Following is my code for server sending webcam. When following server thread run it opens webcam panel and show webcam live video. I write this object to client. Following is the server code :
Code :public void run(){ if(cam!=null){ try{ System.out.println("Prepared to write"); //cam= Webcam.getDefault(); WebcamPanel pnl = new WebcamPanel(cam); JFrame j= new JFrame(); j.add(pnl); j.setVisible(true); //byte[] by = (byte)cam; try{ while(true){ System.out.println("Starting writing..."); // wr = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream())); //wr.write("abc"); //wr.write('\n'); //wr.flush(); objwr= new ObjectOutputStream(clientSocket.getOutputStream()); //wr = new BufferedWriter(objwr); objwr.writeObject(cam); } } catch (Exception ex){ throw new InterruptedException(ex.getMessage()); } finally{ try{ if(wr!=null) { wr.close(); } if(objwr!=null) { objwr.close(); } } catch(Exception ex3){ throw new InterruptedException(ex3.getMessage()); } } //Thread.sleep(0); } catch(InterruptedException ex) { throw new RuntimeException(ex.getMessage()); } } }
Following is the client code :
Code :@Override public void run(){ try{ boolean fl=true; //cam.open(); WebcamPanel pnl; //JFrame j= new JFrame(); //j.add(pnl); //j.setVisible(true); try{ objin= new ObjectInputStream(serverSocket.getInputStream()); while(true){ if(fl) { System.out.println("Setting for 1st time"); cam = (Webcam)objin.readObject(); pnl = new WebcamPanel(cam); JFrame j= new JFrame(); j.add(pnl); j.setVisible(true); } else { System.out.println("for 2nd time"); cam = (Webcam)objin.readObject(); } } //System.out.println("Reading video"); //BufferedReader rdr= new BufferedReader( new InputStreamReader(serverSocket.getInputStream())); //System.out.println(rdr.readLine()); } catch(Exception ex1){ throw new InterruptedException(ex1.getMessage()); } finally{ try{ if(objin!=null) { objin.close(); } } catch(Exception ex3){ throw new InterruptedException(ex3.getMessage()); } } } catch(InterruptedException ex){ throw new RuntimeException(ex.getMessage()); } }
And im getting this error while reading from client side
Exception in thread "Thread-0" java.lang.RuntimeException: writing aborted; java.io.NotSerializableException: com.github.sarxos.webcam.Webcam
at VideoClient.TCameraReader.run(TCameraReader.java:9 3)
and in server side :
Exception in thread "Thread-3" java.lang.RuntimeException: com.github.sarxos.webcam.Webcam
at VideoServer.TCameraWriter.run(TCameraWriter.java:9 0)
Read the API for the methods you are using:Quote:
Exception in thread "Thread-0" java.lang.RuntimeException: writing aborted; java.io.NotSerializableException:
docs.oracle.com/javase/6/docs/api/java/io/ObjectOutputStream.html
You haven't posted the appropriate code for anyone to say that the object you are writing is Serializable.
What do you mean by "cam"?Quote:
used for sending cam
How are bytes of data obtained from "cam" that they can be sent to another program via sockets? Often that is down by reading from an output stream provided by a method in the class.
You posted a NotSerializableException was thrown. The code you posted attempts to Serialize an object. If you read the API for the method writeObject, you would find the following:
So whatever it is you are trying to serialize in your current code - whatever 'Webcam' class is, it does not implement Serailizable.Quote:
NotSerializableException - Some object to be serialized does not implement the java.io.Serializable interface.
Given I don't fully understand your problem beyond that, that is as much information as I can provide.