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 9 of 9

Thread: how to send video from sockets

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to send video from sockets

    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.


  2. #2
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to send video from sockets

    anyone please reply provide me reference , tutorials etc

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to send video from sockets

    What code do you have now? Can you write and read data over a socket?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: how to send video from sockets

    ...and commenting in the chat box that this forum sucks is not doing you any favors.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to send video from sockets

    Quote Originally Posted by Norm View Post
    What code do you have now? Can you write and read data over a socket?
    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 :
     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 :

    @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)

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: how to send video from sockets

    Exception in thread "Thread-0" java.lang.RuntimeException: writing aborted; java.io.NotSerializableException:
    Read the API for the methods you are using:
    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.

  7. #7
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to send video from sockets

    Quote Originally Posted by copeg View Post
    Read the API for the methods you are using:
    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.
    In this API there is not any thing written for sending in streams.
    I used cam object which is object of Webcam class which is used in API
    Can you please tell me any other API which can be used for sending cam via sockets.

    Thanks

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to send video from sockets

    used for sending cam
    What do you mean by "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.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: how to send video from sockets

    Quote Originally Posted by shanalikhan View Post
    In this API there is not any thing written for sending in streams.
    I used cam object which is object of Webcam class which is used in API
    Can you please tell me any other API which can be used for sending cam via sockets.

    Thanks
    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:
    NotSerializableException - Some object to be serialized does not implement the java.io.Serializable interface.
    So whatever it is you are trying to serialize in your current code - whatever 'Webcam' class is, it does not implement Serailizable.

    Given I don't fully understand your problem beyond that, that is as much information as I can provide.

Similar Threads

  1. Replies: 0
    Last Post: November 16th, 2012, 05:25 AM
  2. ServerSocket send data to all Sockets
    By moon_werewolf in forum Loops & Control Statements
    Replies: 5
    Last Post: September 10th, 2012, 02:44 PM
  3. Sockets in JApplet
    By shrey.haria in forum Java Networking
    Replies: 4
    Last Post: September 5th, 2011, 09:45 AM
  4. Replies: 2
    Last Post: March 16th, 2011, 06:32 AM
  5. Java sockets help
    By ma05k1 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 27th, 2010, 05:52 AM