• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple FIle Sending application

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
--------------------------------------------------------------------------------------------------
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Paul: Thanks
There is no need to look into the code anymore, your hint accurately pointed me towards solution
Many Thanks Again...
 
reply
    Bookmark Topic Watch Topic
  • New Topic