Hi guys,
  this is my third question in as many days. I am pasting
code below. it has an ImageServer and a client. the server
is sending a specified file size. on the client side, i get
a IO exception. the message is something like this.
java.IO.exception
  at
sun.awt.image.GIFImageDecoder.readheader<GIFImageDecoder.java:343>

sun.awt.image.GIFImageDecoder.produceImage<GIFImageDecoder.java:>

sun.awt.image.InputStreamImageSource.doFetch<InputStreamImageSource.java:248>

sun.awt.image.ImageFetcher.fetchloop<ImageFetcher.java:221>

sun.awt.image.ImageFetcher.run<ImageFetcher.java:189>

can somebody tell me what it could be. i would really
apprecite any help from you guys. please...............


//// SERVER //////////////////////
import java.net.*;
import java.io.*;

public class ImageServer {

    static final int PORT = 12345;
    static MulticastSocket msocket;
    static byte[] buffer;

    public static void main(String[] args) {
try {
    File fi=new
File("D:\\all_user\\pavan\\multicast\\active.gif");
    FileInputStream bis=new FileInputStream(fi);
    System.out.println("Available(input) = " +
bis.available());

    msocket = new MulticastSocket();

    buffer = new byte[bis.available()];
    bis.read(buffer, 0, bis.available());

    InetAddress address =
InetAddress.getByName("224.50.50.123");
    msocket.joinGroup(address);
    DatagramPacket packet = new DatagramPacket(buffer,
buffer.length, address, PORT );
    System.out.println("Packet size = " +
packet.getLength());
    System.out.println("Address = " + packet.getAddress());

    msocket.send(packet);

}
catch (IOException e) {
    System.out.println("IO error");
    e.printStackTrace();
}
catch (NullPointerException e) {
    System.out.println("Null pointer error (maybe closing
socket)");
    e.printStackTrace();
}
catch (Exception e) {
    System.out.println("Other error");
    e.printStackTrace();
}
    }
}

/////CLIENT ////////////////////
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;
import java.net.*;


public class SecondTest extends JFrame {
    MulticastSocket msocket;
    InetAddress addr;
    final static int PORT=12345;
    DatagramPacket packet;
    Image image;
    public SecondTest(String tes) {
        setTitle(tes);
        byte[] buffer = new byte[256];
try {
    addr = InetAddress.getByName("224.50.50.123");
    System.out.println("address is" + addr);
    System.out.println(" Port is "+ PORT);
    msocket = new MulticastSocket(PORT);
    msocket.joinGroup(addr);
    System.out.println("Created Socket" + msocket);
    System.out.println("Waiting for packets..........");
    msocket.setSoTimeout(70000);
    // The code does not work beyond this.

    try {
        packet = new DatagramPacket (buffer,
buffer.length);
    msocket.receive(packet);
   /* no packets are being received and hence the following
statement is not printed*/
    System.out.println("receiving packet. Size = " +
packet.getLength());
    }
    catch(Exception re) {re.printStackTrace();}
    }


catch (Exception e) {
    System.out.println("Error!");
    e.printStackTrace();
}
System.out.println("The length of buffer is = " +
buffer.length);


        image =
Toolkit.getDefaultToolkit().createImage(packet.getData());
        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(image, 1);

        try {
            tracker.waitForAll();
        } catch (Exception e) {
            image = null;
            System.err.println("Can't load image");
        }
        setSize(500, 400);
        setBackground(Color.yellow);
        setVisible(true);
    }

    public void paint(Graphics g) {
        if (image != null) {
            g.drawImage(image, 50, 50, null);
        }
    }

   }



__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to