aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Simple FIle Sending application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Simple FIle Sending application" Watch "Simple FIle Sending application" New topic
Author

Simple FIle Sending application

Aniruddha Mukherjee
Greenhorn

Joined: Aug 01, 2011
Posts: 3
Hi Friends,

I am new to java socket programming, trying to send some files using it.
I have written a code that sends data from server to client.

I have tested this code in local machine and as well as over lan(by changing the ip address in the code).
In local machine, the code runs quite fine but still shows the error: Connection reset by peer.

But over the lan it always shows the above error, The code tries to send some part of the file but seems like after sending 82KB of data it gives me the error: Connection reset by peer.
While in the client side nothing is received.
I can ping the client and server PC from one another but the code gives me problem...
The server gets connected to client and start sending the file but after sending around 82KB it throws me the error.

Please help me to analyze the code if there is some mistakes or scope of improvement.


The Server Code goes below



The Client Code


The below is the console error
----------------------------------------------------------
Waiting for connection
Connected to /127.0.0.1
no of parts sent 1
26822 from if
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
no of parts sent 2
25822 from if
no of parts sent 3
24822 from if
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
7 Nov, 2011 1:42:30 AM FileServer main
SEVERE: error in flushing
java.net.SocketException: Connection reset by peer: socket write error
7 Nov, 2011 1:42:30 AM FileServer main
SEVERE: error in flushing
java.net.SocketException: Connection reset by peer: socket write error
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
7 Nov, 2011 1:42:30 AM FileServer main
SEVERE: error in flushing
java.net.SocketException: Connection reset by peer: socket write error
7 Nov, 2011 1:42:30 AM FileServer main
SEVERE: error in flushing
java.net.SocketException: Connection reset by peer: socket write error
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
no of parts sent 4
23822 from if
7 Nov, 2011 1:42:30 AM FileServer main
SEVERE: error in flushing
java.net.SocketException: Connection reset by peer: socket write error
7 Nov, 2011 1:42:30 AM FileServer main
SEVERE: error in flushing
java.net.SocketException: Connection reset by peer: socket write error
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
no of parts sent 5
22822 from if
7 Nov, 2011 1:42:30 AM FileServer main
SEVERE: error in flushing
java.net.SocketException: Connection reset by peer: socket write error
7 Nov, 2011 1:42:30 AM FileServer main
SEVERE: error in flushing
java.net.SocketException: Connection reset by peer: socket write error
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
7 Nov, 2011 1:42:30 AM FileServer main
INFO: logging is working
no of parts sent 6
Exception in thread "main" java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.write(Unknown Source)
at java.io.FilterOutputStream.write(Unknown Source)
at FileServer.main(FileServer.java:50)
--------------------------------------------------------------------------------------------------
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

That message means that the computer at the other end of the connection (in your case, the server) has terminated the connection.

In your case that would be because you're using the available() method. I haven't looked at your code to see if you assume that "available = 0" is equivalent to "no more data will be coming" but that would be my guess. Anyway don't use that method because Available Doesnt Do What You Think It Does .
Aniruddha Mukherjee
Greenhorn

Joined: Aug 01, 2011
Posts: 3
@Paul: Thanks
There is no need to look into the code anymore, your hint accurately pointed me towards solution
Many Thanks Again...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple FIle Sending application