Win a copy of Head First Android this week in the Android forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Client sends just 1 character to server (socket reset)

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

I have this strange problem which has ruined my weekend.

I have been developing a client program for a server (which is developed in C). I was able to send full strings + different data types and get response from the server without problem.

Now (even though I think I have not changed anything), the connection resets after receiving first character of a string or first data item (like integer).

I receive this exception (after I receive a single character "V" at server side):

IOException: java.net.SocketException: Connection reset

Your help is very much appreciated.

My code snippet:


[ July 27, 2008: Message edited by: Siamak Saarmann ]
 
Siamak Saarmann
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again. I mad a little progress in debugging the reason.

1- I removed this line:

System.out.println("Server response: " + ir.readLine());

and I no more receive the exception. (what does this mean? The receive socket is synchronous blocking, why the connection is closed?)

2- After removing above line I start to send data:

If I comment th last line (writeByte) all write commands before it are received in server side. As soon as I un-comment the last line, only a single "V" character is received in server side (the server closes the connection?)

What is going on here. I am becoming crazy.

thanks.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to call "os.flush()" after doing all the writing, so any locally-buffered data is sent to the other end before you try to read the response.
reply
    Bookmark Topic Watch Topic
  • New Topic