Page 1 of 2 12 LastLast
Results 1 to 20 of 39
  1. #1
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Unhappy java networking problem

    i am having a problem with this program.....server is getting connected and no runtime exceptions or compilation errors are being shown but the file is not getting copied....i have observed that the run method inside the server program is not getting executed....plz help me solve this problem....


    thanks in advance....


    any problem with the logic plz let me know the corrected one...


    Java Code:
    
    
    
    
                                                                  //**********************this is server program*************************
    
    import java.io.IOException;
    import java.io.PrintStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    
    import java.io.*;
    
    public class MultiThreadServer implements Runnable {
       Socket csocket;
       MultiThreadServer(Socket csocket) {
          this.csocket = csocket;
       }
    
       public static void main(String args[]) 
       throws Exception {
          ServerSocket ssock = new ServerSocket(1234);
          System.out.println("Listening");
          while (true) {
             Socket sock = ssock.accept();
             System.out.println("Connected");
    
             new Thread(new MultiThreadServer(sock)).start();
    
      }
    }
       public void run() {
    
              System.out.println("entered in run");
          try {
    
              System.out.println("entered in run try");
             
              byte[] mybytearray = new byte[1024];
    
              InputStream is = sock.getInputStream();
    
              File file = new File("D:/MyProject/src/Sumanth/WebServer/AnuFileServer/mani.txt");
    
              FileOutputStream fos = new FileOutputStream(file);
    
              BufferedOutputStream bos = new BufferedOutputStream(fos);
    
              int bytesread = is.read(mybytearray,0,bytesRead);
    
               bos.write(mybytearray,0,bytesread);
    
               System.out.println("bos object"+bos);
    
               bos.close();
    
               
    
    
          }
          catch (IOException e) {
             System.out.println(e);
          }
       }
    }
    
    
    
    
                                                                                    //*********************this is client program**************
    
    
    import java.net.*;
    
    import java.lang.reflect.*;
    
    import java.lang.Class;
    
    import java.io.*;
    
    import java.awt.event.*;
    
    import java.awt.*;
    
    import java.util.*;
    
    
    
    import org.apache.commons.io.FileUtils;
    
    public class Client2Using extends Frame implements ActionListener{
    
        Button b1,b2,b3;Socket socket;
    
        TextArea t;
    
        TextField text;
    
        public Client2Using(){
    
    
         setLayout(new FlowLayout());
    
    
          b1 = new Button("start server");
    
          b2 = new Button("File Upload");
    
          b3 = new Button("Show File Contents");
    
          t = new TextArea(10,10);
    
    
          text = new TextField();
    
          this.add(text);
    
    
    
          b1.addActionListener(this);
    
          b3.addActionListener(this);
    
          
          add(t);
          add(b1);
    
          add(b2);
    
          add(b3);
    
    
    
        }
    
    
        public void actionPerformed(ActionEvent e){
    
    
            if(e.getSource()==b1){
    
    
    
                met();
    
               
    
    
            }
    
            if(e.getSource()==b3){
    
    
               met1();
    
    
            }
    
    
    
        }
    
    
       public void met(){
    
    
         System.out.println("gfskjdfgksdfgkfd");
    
    
        try{
    
    
    
            
             
        
    
             Socket socket = new Socket("localhost",1234);
    
     
    
             this.socket = socket;
    
    
             System.out.println("Server Started");
    
           
    
    
            }catch(Exception e){e.printStackTrace();}
    
    
    
       }
    
    
       public void met1(){
    
         try{
    
    
           File myfile = new File("D:/MyProject/src/Sumanth/WebServer/MyFrame.java");
    
           byte[] mybytearray = new byte[(int) myfile.length()];
    
           BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myfile));
    
           bis.read(mybytearray,0,mybytearray.length);
    
           OutputStream os = socket.getOutputStream();
    
           os.write(mybytearray,0,mybytearray.length);
    
           os.flush();
    
           
    
           System.out.println("os object"+os);
    
    
           }catch(Exception e){e.printStackTrace();}
    
    
    
      }
    
        public static void main(String args[]){
    
       
            Client2Using f = new Client2Using();
    
            f.setVisible(true);
    
            f.setSize(100,100);
    
            }
    
      }
    Last edited by snowhite; 04-24-2012 at 06:04 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: java networking problem

    Please use [code] tags [/code] when posting code, as that lot is nigh on unreadable without them.
    The only bit I can read that looks odd to me:
    Java Code:
    while (true) {
       Socket sock = ssock.accept();
       System.out.println("Connected");
       new Thread(new MultiThreadServer(sock)).start();
    }
    Do you really want to produce a never end load of threads like that?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: java networking problem

    What does the debug print out show for the server?
    Add some more printlns to show the rest of the execution in the run method and the values of the variables as they are changed.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: java networking problem

    Quote Originally Posted by snowhite View Post
    java networking problem
    And you didn't go through the forum lists where you would have seen that there is a separate section for those?

    Moved from Advanced Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Default Re: java networking problem

    Quote Originally Posted by Norm View Post
    What does the debug print out show for the server?
    Add some more printlns to show the rest of the execution in the run method and the values of the variables as they are changed.
    i have added the printlns in run() method which is the reason how i came to know that run is not getting executed inside the server class

  6. #6
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Default Re: java networking problem

    yes i want multiple clients processing server....but my problem is with the file downloading...plz check the code and let me know abt the problem and solution....thanks

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

    Default Re: java networking problem

    What does the debug print out show for the server?


    The code does not compile. You need to fix the compiler errors first.
    Last edited by Norm; 04-24-2012 at 06:12 PM.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Default Re: java networking problem

    yeah i am sorry i am new to this forum...so i didnt go through the lists properly ..thanks anyway for transferring me to the correct thread...

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

    Default Re: java networking problem

    The code does not compile. You need to fix the compiler errors first.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: java networking problem

    Quote Originally Posted by snowhite View Post
    yes i want multiple clients processing server....but my problem is with the file downloading...plz check the code and let me know abt the problem and solution....thanks
    Whoops, sorry.
    I entirely missed the call to accept() there.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Default Re: java networking problem

    mr norm i am not getting any compiler errors...in ur computer u might get some errors relating to the file path ....so plz do give ur own file path....and other errors might be relating to the classpath or package names...plz let me know wht compiler error it gives u...thank u

  12. #12
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Default Re: java networking problem

    hello tolls ,do u have any solution to my problem...?...i would be pleased to know the problem.....plz try to resolve it or let me know the problem if u get it....thanks a lot...

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

    Default Re: java networking problem

    i am not getting any compiler errors
    You need to find the compiler errors and fix them so the code will execute correctly. What compiler are you using?
    It is important that you use a compiler that finds the errors.
    Did you post the correct code? Make sure that the posted code is the right version.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Default Re: java networking problem

    Quote Originally Posted by Norm View Post
    You need to find the compiler errors and fix them so the code will execute correctly. What compiler are you using?
    It is important that you use a compiler that finds the errors.
    Did you post the correct code? Make sure that the posted code is the right version.


    ur reply to me was blank.....nothing was displayed on the screen...plz do it again

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

    Default Re: java networking problem

    That was the full text of what I posted.
    How are you compiling the program? What compiler are you using?
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Default Re: java networking problem

    i am using java compiler...

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

    Default Re: java networking problem

    What is the name of the program and how are you using it?
    If you don't understand my response, don't ignore it, ask a question.

  18. #18
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Default Re: java networking problem

    when u execute my program----2 button tasks are there.....

    1---first click on the "start server" button

    2----after starting the server i want to copy a file from the server socket to the client socket .....assume from one folder in some c drive and display the content of the file in the text area of the frame..this has to be done by clicking the third button "copy file contents".

    3----i have not written code for "upload file button" ,so need not use it....

    the 2nd task which i have mentioned above is not happening...although the 1st one works fine...

    plz give me some solution to my program...its been 3 days....but no answer for me.....thanks in advance...i hope i was clear in explaing abt my program...

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

    Default Re: java networking problem

    The code you posted does not compile without errors. Do you have a new version of the code that compiles without errors?
    Please post the code that you are using for testing. The current code will not compile for me so I can not test the program.
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    snowhite is offline Member
    Join Date
    Apr 2012
    Posts
    23
    Rep Power
    0

    Default Re: java networking problem

    Quote Originally Posted by Norm View Post
    The code you posted does not compile without errors. Do you have a new version of the code that compiles without errors?
    Please post the code that you are using for testing. The current code will not compile for me so I can not test the program.
    why wont my code compile..?i didnt get u...???....i am using the same api and compilers as u use.....its the same java program which imports packages used by hundred's of other programmers.....plz let me know wht the compiler says.....becuz how can i change the code when the logic is same...i am not getting ur question....plz tell me clearly....
    Last edited by snowhite; 04-27-2012 at 11:17 AM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Networking with java
    By munny in forum Networking
    Replies: 8
    Last Post: 11-20-2011, 04:30 AM
  2. New to networking in java...
    By jigglywiggly in forum New To Java
    Replies: 4
    Last Post: 05-25-2010, 08:10 AM
  3. networking problem
    By anurupr in forum Networking
    Replies: 0
    Last Post: 03-15-2010, 03:53 PM
  4. Java networking.
    By tim in forum New To Java
    Replies: 7
    Last Post: 07-16-2009, 10:43 PM
  5. Networking Problem
    By Ambuscade in forum Networking
    Replies: 21
    Last Post: 11-05-2008, 03: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
  •