Client Server problems in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RockyIV
    New Member
    • Apr 2009
    • 3

    Client Server problems in java

    I want to sent a .dat file from the server to the client and have the client put it in an array and display it. My problem is on the server end but i jus dont know what to do. can anyoner please help me, here's what i've got so far:

    Scanner FileOut = new Scanner(new File("test.dat" ));
    byte[] dataOut = new byte[1024];
    dataOut = FileOut.toStrin g().getBytes();

    DatagramPacket outPacket = new DatagramPacket (dataOut, dataOut.length, group, clientPort);

    socket.send(out Packet);
    System.out.prin tln("File sent to client");


    whats missing/ where m i going wrong.
    it's UDP by the way
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    The Scanner.toStrin g() method doesn't do what you might think it does: it just returns a String representation of the Scanner, not the content of the stream it's scanning. Read the API documentation for details.

    kind regards,

    Jos

    Comment

    • RockyIV
      New Member
      • Apr 2009
      • 3

      #3
      would it be possible for you to send me some code that would work for what i am trying to do?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by RockyIV
        would it be possible for you to send me some code that would work for what i am trying to do?
        Read the API documentation for the InputStream class; a link to the documentation can be found in the very first article of this group "Read This First". You should read data from the InputStream and pass it to your destination through the UDP socket. There's no need for a Scanner here; scanners are for text, not binary data.

        kind regards,

        Jos

        Comment

        Working...