CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2008
    Posts
    4

    Byte Array mpeg file

    Hi All!
    im developing a chat room system, where the client can retrieve a file from the server. To make it simple, i have 3 files which the user can retrieve. A Picture, sound, and movie. They are all sent to the client using a sendMedia function which i have created. The Sound and Images are sent to the client fine, but there is a problem with the movie file(.mpeg) I will post the relevant server and client code, and indacate where the problem is occuring:

    Sever Code:

    Code:
    public void sendMedia(String message)
    	{
    		try
    		{
    			
            	//Step 1... 
    			ObjectOutputStream outStream =
    					new ObjectOutputStream(
    							transfer.getOutputStream());
    			
    			if (message.equals("getSound"))
    			{
    				output.println("mess:**** SOUND REQUESTED ****"); 
    				
    				sendFile("cuckoo.au", outStream);
    				
    				output.println("mess:**** SOUND SENT ****"); 
    			}
    			else if (message.equals("getImage"))
    			{
    				output.println("mess:**** IMAGE REQUESTED ****"); 
    	        	 
    				sendFile("car.jpg", outStream);
    				
    				output.println("mess:**** IMAGE SENT ****"); 
    			}
    			else if (message.equals("getMovie"))
    			{
    				output.println("mess:**** MOVIE REQUESTED ****"); 
    	        	 
    				sendFile("moon_walk.mpeg", outStream);
    				
    				output.println("mess:**** MOVIE SENT ****"); 
    			}
    			//To play safe, flush the output buffer...
    			outStream.flush();
    		}
    		catch(IOException ioEx)
    		{
    			ioEx.printStackTrace();	
    		}
    	}
    
    	private static void sendFile(String fileName,
    		ObjectOutputStream outStream) throws IOException
    	{
    		System.out.println("start send file");
    
    		FileInputStream fileIn = new FileInputStream(fileName);
    
    		long fileLen =  (new File(fileName)).length();
    
    		int intFileLen = (int)fileLen;
    
    		byte[] byteArray = new byte[intFileLen];
    
    		fileIn.read(byteArray);
    
    		fileIn.close();
    
    		outStream.writeObject(byteArray); <-------PROGRAM CRASHES HERE
    
    		outStream.flush();
    	}
    And now the client code:

    Code:
    private void getFile(ObjectInputStream inStream, String fileType) 
    	{
    		try
    		{
    
    			byte[] byteArray = (byte[])inStream.readObject();
    	
    	      	FileOutputStream mediaStream = null;
    	
    			if (fileType.equals("SOUND")){
    				mediaStream = 
    					new FileOutputStream
    						("TransferedSound.au");
    				mediaStream.write(byteArray);
    				
    				playMedia frame = new playMedia(fileType);
    
    				frame.setTitle( "Transfered Sound" );
    				frame.setSize(100, 100);
    		      	frame.setVisible(true);
    				
    			}
    			else if (fileType.equals("IMAGE")){
    				mediaStream = 
    				new FileOutputStream
    			("TransferedImage.jpg");
    				
    				mediaStream.write(byteArray);
    				
    				DisplayImage pictureFrame = new DisplayImage();
    				
    				pictureFrame.setTitle( "Trasfered Image" );
    				pictureFrame.setSize(420,310);
    				pictureFrame.setVisible(true);
    			}
    			else if(fileType.equals("MOVIE")){
    				mediaStream = 
    					new FileOutputStream
    				("\TransferedMovie.mpeg");
    				
    				System.out.println("1");
    				
    				mediaStream.write(byteArray);
    				System.out.println("2");
    				playMedia frame = new playMedia(fileType);
    				System.out.println("3");
    
    				frame.setTitle( "Trasfered Movie" );
    				frame.setSize(420,310);
    		      	frame.setVisible(true);
    			}
    		}
    Any Help, or suggestions would be a great help
    thanks

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Byte Array mpeg file

    When you say the program 'crashes', what happens? Do you get any error messages?
    Please post the full text of any error messages, including stack trace.

    Today, most software exists, not to solve a problem, but to interface with other software...
    I.O. Angell
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Apr 2008
    Posts
    4

    Re: Byte Array mpeg file

    oh im so dumb, iv sorted it now. The Client was not setting up as the function was looking for getMovie from the server and getMoive for the client.

    all working good now
    thanks

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Byte Array mpeg file

    Quote Originally Posted by al_se_08
    ... the function was looking for getMovie from the server and getMoive for the client.
    Ouch! don'tcha hate it when that happens...

    Optimism is an occupational hazard of programming: testing is the treatment...
    K. Beck
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured