Results 1 to 3 of 3
  1. #1
    ravian is offline Senior Member
    Join Date
    Nov 2007
    Posts
    115
    Rep Power
    0

    Default Socket programming - accepting files

    I have written a Socket Server that is listening at some port. I am getting input from my client using DataInputStream. Review the code below:

    Java Code:
    DataInputStream input;
    try {
    input = new DataInputStream(MyClient.getInputStream());
    }
    catch (IOException e) {
           System.out.println(e);
    }
    I want the user to send me File objects as well. Is this possible which the code above or I have to make some changes?

    Thanks for your time.

  2. #2
    javagk is offline Member
    Join Date
    Nov 2007
    Posts
    12
    Rep Power
    0

    Default

    Yes, you may send files using Socket client. use FileOutputStream in that case.

    Java Code:
    BufferedOutputStream bos = new BufferedOutputStream
                            (new FileOutputStream("fileName.txt"));
    Make sure to catch exceptions.

    Happy coding.

  3. #3
    ravian is offline Senior Member
    Join Date
    Nov 2007
    Posts
    115
    Rep Power
    0

Similar Threads

  1. Socket programming - port issues
    By ravian in forum Networking
    Replies: 2
    Last Post: 11-07-2007, 11:24 AM
  2. Programming Socket Question
    By paul in forum Networking
    Replies: 1
    Last Post: 07-30-2007, 08:26 PM
  3. send files through socket
    By bbq in forum Advanced Java
    Replies: 1
    Last Post: 06-05-2007, 03:08 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
  •