• Post Reply Bookmark Topic Watch Topic
  • New Topic

Uploading a file to a remote computer in a Local Area Network (LAN)  RSS feed

 
Sumit Kumar Yadav
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello there,
I need to upload a file to a remote URL in a LAN network, here is the coding that i have done to do that using URL class (i am not supposed to choose socket programming, as it needs a client and server to run to two computers)



this program runs successfully but does not create and send any file, however if we remove the URL class as well as printstream class, a file will be created of the specified size.
also i am confused that where that file will be saved at the destination computer (if it is sent).
please help me out.
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add logging to both the client program and the server program. Write your code so that the log gets any exceptions as well as periodic status messages. Check out java.util.logger or log4j.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And by the way, this is NOT logging:



The code inside the catch block simply produces a reference to a String object from the IOException and then discards the reference. So basically nothing happens. If you aren't going to handle the exception then you should at least write it to something external. The simplest thing would be



but if your program is using a logging framework then writing an error log wouldn't hurt.
 
Henry Wong
author
Sheriff
Posts: 23280
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sumit Kumar Yadav wrote:
this program runs successfully but does not create and send any file, however if we remove the URL class as well as printstream class, a file will be created of the specified size.
also i am confused that where that file will be saved at the destination computer (if it is sent).
please help me out.


The HTTP protocol isn't really a good protocol to do file uploading, as that is not what it was designed for. What you are doing doesn't work, because the URL that you specify means to get the main index html from from the web server at that location. Sending a bunch of data, and likely, not correctly formatted post data will at best get ignored, and at worst, generate an error (which you don't bother reading regardless).

Henry
 
Sumit Kumar Yadav
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry sir, then what i supposed to do for sending a file to a computer connected via LAN... i cannot use the socket programming to do this (as it need two separate client and server programs)..
Actually i have to check the uploading and downloading speed of a LAN network, as i am building a software to do that.. Please help me out
 
Sumit Kumar Yadav
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also when i added the printStackTrace() method, it throws exceptions as follows :
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
at sun.net.www.http.HttpClient.New(HttpClient.java:290)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1090)

i am not geeting what it says so please help me out...
what's the problem with the above code ?? why it is not working..
Do i need to use HttpURLConnection class to do this...
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of access do you have to the other computer - FTP, HTTP, SMB/shared directory, WebDAV, something else? You have to have something that is prepared to accept files.

i have to check the uploading and downloading speed of a LAN network

So the fact that a file gets stored at the receiving machine is actually irrelevant? What you're really asking is about the implementation of this earlier idea of yours?
 
Sumit Kumar Yadav
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir, as i am working on a local computer so i do not know exactly.. please guide me through this what i need to do ? In my view, on the other computer there must be Http access.
yes sir, thats correct... as i have to check the throughput so i thought of sending a file and calculating the time duration.
 
Sumit Kumar Yadav
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i use UDP sockets to send data packets of some specific size without building any server side program... does that help ??
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need something active on the other side, there's just no way around that. That's why something like http://www.speedtest.net/ runs Flash code on your machine.

But let's take a step back: what is the point of establishing how fast one might upload or download a file if there is no way to actually upload or download? That sounds a bit pointless to me. Is this a task you have given yourself? If so, you may want to rethink it. If you have been given this task by someone else, you should ask that person what the exact purpose of it is.
 
Sumit Kumar Yadav
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir, as i am building a LAN testing software so i want that application to test the bandwidth speed of the network.. that is why i am thinking of doing this.
if that is pointless then please suggest me another solution to achieve this... it is urgent as i have to submit my application in the coming week. what should i do to test the bandwidth speed of the network??
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you define "the speed of the network"? There is a theoretical upper bound on the physical hardware and the switches being used. For example, network cards these days are often ready for Gigabit Ethernet. But you only get that if the cable supports it, like Cat-5 cable. And of course your switches also need to support it.

Other than that, you can at best measure the speed between two machines that both have sending and receiving clients. The amount of data you can transmit using raw TCP packets is higher than the amount of, say, HTTP traffic, because that comes with a lot of overhead due the network layer(s) in between.

So you need to think of what you can reasonably measure. if you want to measure traffic in both directions then you need active components on both sides, no way around that. If you can't make that happen, then the overall design is flawed.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!