Results 1 to 20 of 39
Thread: java networking problem
- 04-24-2012, 12:13 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
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.
- 04-24-2012, 12:33 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,470
- Rep Power
- 16
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:
Do you really want to produce a never end load of threads like that?Java Code:while (true) { Socket sock = ssock.accept(); System.out.println("Connected"); new Thread(new MultiThreadServer(sock)).start(); }Please do not ask for code as refusal often offends.
- 04-24-2012, 01:31 PM #3
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.
- 04-24-2012, 04:28 PM #4
- 04-24-2012, 06:02 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
- 04-24-2012, 06:05 PM #6
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
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
- 04-24-2012, 06:06 PM #7
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.
- 04-24-2012, 06:06 PM #8
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
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...
- 04-24-2012, 06:17 PM #9
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.
- 04-24-2012, 06:28 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,470
- Rep Power
- 16
- 04-25-2012, 08:57 AM #11
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
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
- 04-25-2012, 08:58 AM #12
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
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...
- 04-25-2012, 12:46 PM #13
Re: java networking problem
You need to find the compiler errors and fix them so the code will execute correctly. What compiler are you using?i am not getting any compiler errors
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.
- 04-25-2012, 01:20 PM #14
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
- 04-25-2012, 01:22 PM #15
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.
- 04-25-2012, 01:22 PM #16
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
Re: java networking problem
i am using java compiler...
- 04-25-2012, 01:23 PM #17
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.
- 04-26-2012, 09:38 AM #18
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
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...
- 04-26-2012, 12:46 PM #19
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.
- 04-27-2012, 11:14 AM #20
Member
- Join Date
- Apr 2012
- Posts
- 23
- Rep Power
- 0
Re: java networking problem
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.
Similar Threads
-
Networking with java
By munny in forum NetworkingReplies: 8Last Post: 11-20-2011, 04:30 AM -
New to networking in java...
By jigglywiggly in forum New To JavaReplies: 4Last Post: 05-25-2010, 08:10 AM -
networking problem
By anurupr in forum NetworkingReplies: 0Last Post: 03-15-2010, 03:53 PM -
Java networking.
By tim in forum New To JavaReplies: 7Last Post: 07-16-2009, 10:43 PM -
Networking Problem
By Ambuscade in forum NetworkingReplies: 21Last Post: 11-05-2008, 03:12 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks