469,323 Members | 1,614 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

File copy over Network.

dmjpro
2,476 2GB
HI i am starting Java Networking programming with File Copy over Network.
I got a sample code .... but still having some confusions.

Expand|Select|Wrap|Line Numbers
  1. Socket socket = new Socket(ip,port);
  2. OutputStream out = socket.getOutputStream();
  3. out.write(""); //Where it writes to the destined HOST?
  4.  
Please help me.
Can't I give a particular location in destined HOST?

Debasis Jana
Mar 7 '08 #1
9 9347
JosAH
11,448 Expert 8TB
HI i am starting Java Networking programming with File Copy over Network.
I got a sample code .... but still having some confusions.

Expand|Select|Wrap|Line Numbers
  1. Socket socket = new Socket(ip,port);
  2. OutputStream out = socket.getOutputStream();
  3. out.write(""); //Where it writes to the destined HOST?
  4.  
Please help me.
Can't I give a particular location in destined HOST?

Debasis Jana
w.r.t. your question at line 3 of your code: yes it writes to the host located at
IP address 'ip'; the host listens to port 'port'. The host should open an InputStream
and read the data stream; the input comes from the client. The host is free to do
anything it wants with the data, so it can also create a file and write the data it
received to the file. As far as that server is concerned it reads bytes from a stream
and does something with it. As far as the client is concerned, it writes bytes to
that output stream to the server.

To answer your last question: yes the client can also write the name of the file
to that output stream. You have to define some form of protocol to which both
your client and server 'obey' because your connection is just a stream of bytes.
You define the meaning of those bytes.

kind regards,

Jos
Mar 7 '08 #2
dmjpro
2,476 2GB
w.r.t. your question at line 3 of your code: yes it writes to the host located at
IP address 'ip'; the host listens to port 'port'. The host should open an InputStream
and read the data stream; the input comes from the client. The host is free to do
anything it wants with the data, so it can also create a file and write the data it
received to the file. As far as that server is concerned it reads bytes from a stream
and does something with it. As far as the client is concerned, it writes bytes to
that output stream to the server.

To answer your last question: yes the client can also write the name of the file
to that output stream. You have to define some form of protocol to which both
your client and server 'obey' because your connection is just a stream of bytes.
You define the meaning of those bytes.

kind regards,

Jos

If I want to copy to that destined machine+particular directory then what should I do ....means what should I give ...as HOST NAME and PORT????
I am getting a connection refused Exception ....

Please Help!
Mar 8 '08 #3
dmjpro
2,476 2GB
If I want to copy to that destined machine+particular directory then what should I do ....means what should I give ...as HOST NAME and PORT????
I am getting a connection refused Exception ....

Please Help!
Jos I need a help here!
Actually when I copy the file over Network there should be username and password of where to be copied.
That's where should I me mention??
And the particular location that where should I mention??
Please Help.

I run a code in my Machine.

Expand|Select|Wrap|Line Numbers
  1. package networking;
  2.  
  3. import java.net.*;
  4. import java.io.*;
  5.  
  6.  
  7. public class lookForPorts {
  8.  
  9.   public static void main(String[] args) throws Exception{
  10.  
  11.     Socket theSocket;
  12.     //String host = "localhost";
  13.     String host = InetAddress.getByName("10.29.32.68").getHostName();
  14.  
  15.     if (args.length > 0) {
  16.       host = args[0];
  17.     }
  18.     for (int i = 0; i < 1024; i++) {
  19.         System.out.println("DMJPRO: =============== " + i);
  20.       try {
  21.         theSocket = new Socket(host, i);
  22.         System.out.println("There is a server on port " + i + " of " + host);
  23.       }
  24.       catch (UnknownHostException e) {
  25.         System.err.println(e);
  26.         break;
  27.       }
  28.       catch (IOException e) {
  29.         // must not be a server on this port
  30.       }
  31.     } // end for
  32.  
  33.   }  // end main
  34.  
  35. }  // end look for ports
  36.  
Here only three ports I getting where I can connect.
So which port I should use here.
I am getting confused.

Debasis Jana!
Mar 8 '08 #4
dmjpro
2,476 2GB
One more thing JOS!
Could you explain "You have to define some form of protocol to which both
your client and server 'obey' because your connection is just a stream of bytes.
You define the meaning of those bytes."????
How should I define a Protocol?

Debasis Jana
Mar 8 '08 #5
JosAH
11,448 Expert 8TB
One more thing JOS!
Could you explain "You have to define some form of protocol to which both
your client and server 'obey' because your connection is just a stream of bytes.
You define the meaning of those bytes."????
How should I define a Protocol?

Debasis Jana
If a client wants to use a service it has to know the ip number of the host that
runs the service *and* its port number. The client can connect to the server
running the service then,

The only means of communication between a server and a client are the two
streams: one for writing and one for reading. If you want to save a file somewhere
on the server's filing system you have to tell the server where you want to store
the file (i.e. you have to give the full path name of the new file on the server) and
you have to send the content you want to have in that file and preferably the size
of the content so the server knows what it can stop saving data and close the
file again. The way you do that (i.e. communicate what and how with the server)
is called the 'protocol'.

You either have to implement an already existing protocol or, when both the
server and the client(s) are made by you, you have to define your own protocol
for that, i.e. the file name, the content and its size have to be send to the server
somehow.

kind regards,

Jos
Mar 8 '08 #6
dmjpro
2,476 2GB
If a client wants to use a service it has to know the ip number of the host that
runs the service *and* its port number. The client can connect to the server
running the service then,

The only means of communication between a server and a client are the two
streams: one for writing and one for reading. If you want to save a file somewhere
on the server's filing system you have to tell the server where you want to store
the file (i.e. you have to give the full path name of the new file on the server) and
you have to send the content you want to have in that file and preferably the size
of the content so the server knows what it can stop saving data and close the
file again. The way you do that (i.e. communicate what and how with the server)
is called the 'protocol'.

You either have to implement an already existing protocol or, when both the
server and the client(s) are made by you, you have to define your own protocol
for that, i.e. the file name, the content and its size have to be send to the server
somehow.

kind regards,

Jos
I want use FTP protocol.
Could you help me to do that.
I think due to firewall I can't connect.
How could I do?

Debasis Jana
Mar 8 '08 #7
dmjpro
2,476 2GB
I want use FTP protocol.
Could you help me to do that.
I think due to firewall I can't connect.
How could I do?

Debasis Jana

Right now i made my local machine both ....Client and Server.
So ConnectException raised.
How could i configure FTP protocol in my Machine?

Debasis Jana
Mar 8 '08 #8
JosAH
11,448 Expert 8TB
Right now i made my local machine both ....Client and Server.
So ConnectException raised.
How could i configure FTP protocol in my Machine?

Debasis Jana
Google is your friend.

kind regards,

Jos
Mar 8 '08 #9
dmjpro
2,476 2GB
Google is your friend.

kind regards,

Jos
Thank you JOS for being with me for a long time with this Thread.
Actually I got a library org.apache.commons.net.********.
It's a very fantastic code.
Now do I need to define the protocol on Server to make it as FTP through Java Code?
Or something else(S/W) will help me to do that.

Please help!

Debasis Jana.
Mar 10 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Paul | last post: by
1 post views Thread by John Wright | last post: by
3 posts views Thread by Barry Flynn | last post: by
9 posts views Thread by Mantorok | last post: by
1 post views Thread by =?Utf-8?B?UmFkZW5rb19aZWM=?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.