This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Sockets and Internet Protocols and the fly likes Socket scenario missing data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Socket scenario missing data" Watch "Socket scenario missing data" New topic
Author

Socket scenario missing data

Tom Henricksen
Ranch Hand

Joined: Mar 23, 2004
Posts: 136

I have taken some socket examples and changed them to fit my needs. My code does everything correctly except some characters are missing. This is what it should be:
MSH|^~\&|BEMRX||PYXISRX||200701031628||^~\&^RDE||P|2.3|
this is what I get:
SH|^~\&|BEMRX||PYXISRX||200701031624||^~\&^RDE||P|2.3|
So it cuts off the first letter.
Here is my code
Client Code:

Server Code:


It has to be the infile.read() but how do I move the read back?

Thanks,
Tom
[ January 08, 2007: Message edited by: Tom Henricksen ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

Originally posted by Tom Henricksen:
It has to be the infile.read() but how do I move the read back?


Move the what back now?
infile.read() reads a single character, then the next line reads until EOL, so it is the cause of your problem. The correct way to read a line from a file would look like your server code:


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Tom Henricksen
Ranch Hand

Joined: Mar 23, 2004
Posts: 136

Thanks Joe
Even though your a bartender I owe you a virtual beer.

Tom
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket scenario missing data