Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 42
  1. #21
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

  2. #22
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    someone?
    i thought that the array can't to hold so much cells so i try to do some arrays
    but it dont help because the program suddenly sent 70 bytes instead of 100 bytes
    and from there the program stuck...

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    Can you post the code and the println() debug output that shows what you are talking about?

  4. #24
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Can you post the code and the println() debug output that shows what you are talking about?
    CLIENT:
    Java Code:
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    
    public class TryC extends JFrame
    {
        private static final byte BYTE2READ = 100;
        private Socket socket;
        private DataOutputStream toServer;
        private File file;
        private RandomAccessFile fromFile;
        private JTextArea jta = new JTextArea();
        
        public TryC()
        {
            add(new JScrollPane(jta));
            pack();
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
            try
            {
                socket = new Socket("localhost", 8000);
                toServer = new DataOutputStream(socket.getOutputStream());
                file = new File("******");
                fromFile = new RandomAccessFile(file, "r"); 
                toServer.writeUTF(file.getName());
                toServer.writeInt((int)fromFile.length());
                jta.append(fromFile.length() + "\n");
                int fromI, len;
                byte[] bytes = new byte[(int)fromFile.length()];
                fromFile.read(bytes);
                for (int i = 0; i < bytes.length; i+= BYTE2READ)
                { 
                    fromI = i;
                    len = (fromI+BYTE2READ > bytes.length) ? bytes.length%BYTE2READ : BYTE2READ; 
                    jta.append("fromI: " + fromI + " len: " + len + "\n");
                    toServer.writeInt(fromI);
                    toServer.writeInt(len);
                    toServer.write(bytes, fromI, len);
                    toServer.writeBoolean(i+BYTE2READ < bytes.length);
                }             
                fromFile.close();
                toServer.close();
            }
            catch (IOException ex) {ex.printStackTrace();}
        }
    
        public static void main(String[] args)
        {
            new TryC();
        }
    }
    SERVER:
    Java Code:
    import javax.swing.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    
    public class TryS extends JFrame
    {
        private ServerSocket serverSocket;
        private Socket socket;
        private DataInputStream fromClient;
        private File file;
        private RandomAccessFile toFile;   
        private JTextArea jta = new JTextArea();
    
        public TryS()
        {
            add(new JScrollPane(jta));
            jta.append(new Date() + "\n");
            
            setSize(200, 200);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
            
            try
            {
                serverSocket = new ServerSocket(8000);
                socket = serverSocket.accept();
                jta.append("connect\n");   
                fromClient = new DataInputStream(socket.getInputStream());
                file = new File(fromClient.readUTF());
                toFile = new RandomAccessFile(file, "rw");
                boolean keepReading = true;
                byte[] bytes = new byte[fromClient.readInt()];   
                int fromI, len;
                while (keepReading)
                {
                    fromI = fromClient.readInt();
                    len = fromClient.readInt();
                    jta.append("read "+fromClient.read(bytes, fromI, len)+"\n");
                    keepReading = fromClient.readBoolean();            
                }               
                toFile.write(bytes);
                toFile.close();
                fromClient.close();
                jta.append("Done");
            }
            catch (IOException ex) {}
        }    
        
        public static void main(String[] args)
        {
            new TryS();
        }
    }
    this the original program that worked if the file is a small
    server DEBUG output:
    Java Code:
    connect
    read 100
    read 100
    read 100
    read 100
    .......
    read 100
    read 100
    read 78
    client DEBUG output:
    Java Code:
    1226502
    fromI: 0 len: 100
    fromI: 100 len: 100
    fromI: 200 len: 100
    fromI: 300 len: 100
    fromI: 400 len: 100
    fromI: 500 len: 100
    fromI: 600 len: 100
    fromI: 700 len: 100
    fromI: 800 len: 100
    fromI: 900 len: 100
    ................
    fromI: 158900 len: 100
    fromI: 159000 len: 100
    fromI: 159100 len: 100
    fromI: 159200 len: 100
    in the client DEBUG output one time it send 800000 bytes i dont know why now
    it is less but as you see there is a problem..
    i dont save my try to handle that with some arrays because it send only 10000 bytes and than stop so i thought that worng way..

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    Your debug output should include the total bytes processed so far. Hard to tell how many bytes were sent by the client and how many were received by the server.

    1226502
    When printing debug output it helps to label numbers etc.
    Is that the size of the file? The debug output only goes to 159200.
    There's a lot of data left.

    there is a problem
    Not sure what the problem is. You have a file with 1226502 bytes you want to send from a client to a server. You are sending it in 100 byte blocks. After sending 159200 bytes the program stops???. I don't know how many bytes the server receives (you need to add to your debug output).

  6. #26
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    i try to sent 1024 bytes(1 kb) in each time and in the 3th running it worked, file with size 1.16mega sent..
    but it didn't work anymore..
    Java Code:
            try
            {
                serverSocket = new ServerSocket(8000);
                socket = serverSocket.accept();
                jta.append("connect\n");   
                fromClient = new DataInputStream(socket.getInputStream());
                file = new File(fromClient.readUTF());
                toFile = new RandomAccessFile(file, "rw");
                boolean keepReading = true;
                byte[] bytes = new byte[fromClient.readInt()];   
                int fromI, len;
                int b_read = 0;
                while (keepReading)
                {
                    fromI = fromClient.readInt();
                    len = fromClient.readInt();
                    b_read+= fromClient.read(bytes, fromI, len);
                    jta.append("read " + b_read + "\n");
                    keepReading = fromClient.readBoolean();            
                }               
                toFile.write(bytes);
                toFile.close();
                fromClient.close();
                jta.append("Done");
            }
    in the server i want to see how much bytes reads but it didnt work it print all time 1024..

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    Not sure what you are saying.
    b_read+= fromClient.read(bytes, fromI, len);
    Break that up into two statements and display both parts: How much was read and how much has been read so far.

  8. #28
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Not sure what you are saying.

    Break that up into two statements and display both parts: How much was read and how much has been read so far.
    but that the most important part..
    why that didnt work anymore if one time that worked?

  9. #29
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    Are you sure it worked?

  10. #30
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Are you sure it worked?
    yea, i saw the image..

  11. #31
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    Does the same code sometimes work and some times not work.
    Or was the code changed from one test to another?

    Is it still working sometimes and not others?

    A debugging technique:
    Write a file containing a known series of numbers or bytes. For example: 12345678901234567890 or 0x0102030405060708090a0b0c0d0e0f10 repeated many times to make a large file.
    Send the file and have the file receiver look at it byte by byte to see if it is receiving exactly what is being sent. Since it knows byte by byte what it should read it can test the incoming bytes against what is expected.

  12. #32
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Does the same code sometimes work and some times not work.
    Or was the code changed from one test to another?

    Is it still working sometimes and not others?

    A debugging technique:
    Write a file containing a known series of numbers or bytes. For example: 12345678901234567890 or 0x0102030405060708090a0b0c0d0e0f10 repeated many times to make a large file.
    Send the file and have the file receiver look at it byte by byte to see if it is receiving exactly what is being sent. Since it knows byte by byte what it should read it can test the incoming bytes against what is expected.
    yes it sometimes finsih to sent and sometime not..
    i call that a random bytes sending...
    each runnnig the number of bytes that sent is different..

  13. #33
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    each runnnig the number of bytes that sent is different.
    Try the technique I mentioned above to see what bytes are not being sent or received.

  14. #34
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    i dont understand very good what do you worte in the tecnique..

  15. #35
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    The idea is to send data that you know and can recognize immediately when you are missing parts of it as you receive that data.
    Take the simple case of sending this: 123456789101112....
    The receiving program will read the first byte and check if it is =1, then the second =2 and the third =3 etc If there is any problem with the transmission the receiving program will know where it occurs.
    For example after reading the 1234th byte which should have the value 1234, if it does not, then there was data lost at that point.

  16. #36
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    The idea is to send data that you know and can recognize immediately when you are missing parts of it as you receive that data.
    Take the simple case of sending this: 123456789101112....
    The receiving program will read the first byte and check if it is =1, then the second =2 and the third =3 etc If there is any problem with the transmission the receiving program will know where it occurs.
    For example after reading the 1234th byte which should have the value 1234, if it does not, then there was data lost at that point.
    and why that go to help me?
    if the problem in this case appears in the 1234th byte in the next time the problem appears at another byte..
    i told you that randomaly..

  17. #37
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    You need to find out what kind of error it is and what is causing it.
    If its a random error, then its not your program. It would be something outside of your program.

    Can you describe when the error occurs? And what the error is?
    Does it send n bytes successfully first then miss some bytes and then send the rest ok?
    So there are some bytes missing in the middle of the file.
    Or does it send unknown bytes that are not part of the file?
    Or what?

  18. #38
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    You need to find out what kind of error it is and what is causing it.
    If its a random error, then its not your program. It would be something outside of your program.

    Can you describe when the error occurs? And what the error is?
    Does it send n bytes successfully first then miss some bytes and then send the rest ok?
    So there are some bytes missing in the middle of the file.
    Or does it send unknown bytes that are not part of the file?
    Or what?
    there is no error..
    no, its sent n bytes and than it need to sent more(1024b) but it sent less than it
    and after that the program doesnt continue but the compiler(i run that from the compiler)
    show me that the program still working..

  19. #39
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    the compiler
    I don't understand what you mean here. You don't run a program from a compiler.

    after that the program doesnt continue
    Which program are you talking about here, client or server?
    Can you see the consoles for both the client and the server program?

    Can you send a file of 1000 bytes ok? And do it more than once?
    If so, how about a file of 100000 bytes. Again more than once.
    If so, then try a file of 1000000 bytes.

    If at any point the file can't be sent more than once, save the debug output from both the server and the client and post it here.

  20. #40
    0xHexaDecimal is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    I don't understand what you mean here. You don't run a program from a compiler.


    Which program are you talking about here, client or server?
    Can you see the consoles for both the client and the server program?

    Can you send a file of 1000 bytes ok? And do it more than once?
    If so, how about a file of 100000 bytes. Again more than once.
    If so, then try a file of 1000000 bytes.

    If at any point the file can't be sent more than once, save the debug output from both the server and the client and post it here.
    ok. i try it tomrrow..
    in my country now the time is 00:05

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. send file via client - server model
    By spasavvas in forum Networking
    Replies: 15
    Last Post: 08-13-2010, 11:45 AM
  2. how to send mp3 file from server to client
    By Jigga008 in forum Networking
    Replies: 0
    Last Post: 12-01-2009, 12:02 PM
  3. Server socket - send image to client
    By Hinty in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 07:39 AM
  4. send/read int in a client/server app
    By dim_ath in forum New To Java
    Replies: 2
    Last Post: 01-03-2008, 01:03 PM
  5. how to send .jar files client to server
    By gobinathm in forum Networking
    Replies: 1
    Last Post: 12-25-2007, 04:05 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
  •