Results 1 to 9 of 9
  1. #1
    nadia is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default Sending .GIF files over the network

    Hi
    I am making A simulation of SMTP through ServerSocket & Socket
    i need to send GIF image from sever to client... When i send image as an ImageIcon it goes Successfully... But animated .Gif file loses its animation.......Can any1 provide me wid a remedy

  2. #2
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    Large binary files must be MIME encoded to send over SMTP

  3. #3
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    I tried with one animated gif and it works, following is the code

    import java.net.*;
    import java.io.*;

    public class TransServer{
    public static void main(String arg[]){
    try{
    ServerSocket sck=new ServerSocket(1000);
    System.out.println("Server running...");
    Socket socket=sck.accept();
    InputStream is=socket.getInputStream();
    int ch=0;
    FileOutputStream fos=new FileOutputStream("d:\\test.gif");
    while(true){
    ch=is.read();
    if(ch==-1)
    break;
    fos.write(ch);
    }
    }
    catch(Exception e){}
    }
    }


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

    public class TransClient{
    public static void main(String arg[]){
    try{

    Socket socket=new Socket("127.0.0.1",1000);
    OutputStream os=socket.getOutputStream();
    int ch=0;
    FileInputStream fis=new FileInputStream("c:\\a1.gif");
    while(true){
    ch=fis.read();
    if(ch==-1)
    break;
    os.write(ch);
    os.flush();
    }
    }
    catch(Exception e){}
    }
    }

  4. #4
    nadia is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default I try this file & it failed... lost a bit of animation

    Quote Originally Posted by dswastik View Post
    I tried with one animated gif and it works, following is the code

    import java.net.*;
    import java.io.*;

    public class TransServer{
    public static void main(String arg[]){
    try{
    ServerSocket sck=new ServerSocket(1000);
    System.out.println("Server running...");
    Socket socket=sck.accept();
    InputStream is=socket.getInputStream();
    int ch=0;
    FileOutputStream fos=new FileOutputStream("d:\\test.gif");
    while(true){
    ch=is.read();
    if(ch==-1)
    break;
    fos.write(ch);
    }
    }
    catch(Exception e){}
    }
    }


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

    public class TransClient{
    public static void main(String arg[]){
    try{

    Socket socket=new Socket("127.0.0.1",1000);
    OutputStream os=socket.getOutputStream();
    int ch=0;
    FileInputStream fis=new FileInputStream("c:\\a1.gif");
    while(true){
    ch=fis.read();
    if(ch==-1)
    break;
    os.write(ch);
    os.flush();
    }
    }
    catch(Exception e){}
    }
    }
    I have attached file but Java forum uploaded that as JPG see what u recieve...
    THANKS 4 ur help
    Attached Thumbnails Attached Thumbnails Sending .GIF files over the network-emailanim.jpg  

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Close outputstream

    Shouldn't you also be closing the OutputSteam and the FileOutputStream to make sure that all data is output/flushed?

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    As said above closing streams might be an issue. Testing with jpg wont be of much of help.

  7. #7
    nadia is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default you TRY SOME large image file..

    Quote Originally Posted by dswastik View Post
    As said above closing streams might be an issue. Testing with jpg wont be of much of help.
    i uploaded .gif file but JAVA FORUMS made it .jpg.... Anywayz you may try any ither larger image file...
    this method flops.basically Java doesnt support GIF ENCODER....
    I have planned to use GIF4J Encoder. But can u tell me how to load .gif file in JTextPane .(not as ImageIcon)cuz that loses image info and i need to send StyledDocument for that JTextPane over network keeping GIF images Animation

  8. #8
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    I tried with the attached image as well, and it works without any issues. I am trying to have a look on your other issue, i.e. image in JTextPane.

  9. #9
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default worked with html support

    //java code
    import javax.swing.*;
    import java.io.*;
    import java.net.*;
    class AnimatedImage {

    public static void main(String[] args) throws Exception {
    //JEditorPane jep = new JEditorPane();
    JTextPane jep = new JTextPane();
    File file = new File( "c:\\test.html" );
    URL url = file.toURI().toURL();
    jep.setPage(url);
    JFrame frm=new JFrame();
    frm.setSize(400,400);
    frm.add(jep);
    frm.setVisible(true);

    }
    }

    //I created one html page as test.html under c:\ which contains the source of the image

    following is the source
    <img src="emailanim.gif">
    Last edited by dswastik; 12-30-2008 at 12:00 PM.

Similar Threads

  1. sending file over network
    By qwerty in forum Networking
    Replies: 6
    Last Post: 04-25-2009, 01:55 AM
  2. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM
  3. Sending files over sockets!
    By rameshraj in forum Networking
    Replies: 2
    Last Post: 05-30-2008, 10:18 PM
  4. sending jar files from client to server?
    By gobinathm in forum New To Java
    Replies: 2
    Last Post: 11-13-2007, 05:12 AM

Posting Permissions

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