Problem sending data over a stream

Hi,

I am having a problem sending the following string over a stream from server to client.

strUserName ="QTQ";

param ="hi";

Send the following: (""+CHAT2ALL+strUserName+(char)(220)+param);

which when written or sent or recieved should be "104QTQ躧i"

But when i send it the client recieves it as : " 104Q躧i", which is incorrect and corrupt in a way, before the 104 where there is a 2 space gap 2 characters like a square appear.. which for some reason can't get pasted.

Thanks

[641 byte] By [QTQa] at [2007-11-26 18:05:58]
# 1
Just thought I'd add a point that I also just tried it with normal text so basically any text i send it adds the funky characters before it for some reason ?Thanks
QTQa at 2007-7-9 5:36:49 > top of Java-index,Archived Forums,Socket Programming...
# 2
Don't concatenate your control bytes into the String or they will be turned into Unicode. Send them separately.
ejpa at 2007-7-9 5:36:49 > top of Java-index,Archived Forums,Socket Programming...
# 3
Thanks, well even if I send ("Hi"); it will still recieve it with unicode before it.. and what i've noticed now is that it only does it for the first set of data it recieves.. after which it recieves the rest normally.
QTQa at 2007-7-9 5:36:49 > top of Java-index,Archived Forums,Socket Programming...
# 4
You must be writing chars and reading bytes then? or doing something else asymmetric?
ejpa at 2007-7-9 5:36:49 > top of Java-index,Archived Forums,Socket Programming...
# 5

> Hi,

>

> I am having a problem sending the following string

> over a stream from server to client.

> > strUserName = "QTQ";

> param = "hi";

> Send the following:

> (""+CHAT2ALL+strUserName+(char)(220)+param);

>

> which when written or sent or recieved should be

> "104QTQ躧i"

>

> But when i send it the client recieves it as : "

> 104Q躧i", which is incorrect and corrupt in a

> in a way, before the 104 where there is a 2 space gap

> 2 characters like a square appear.. which for some

> reason can't get pasted.

The io schemes for the two endpoints of a socket communications should be properly paired and their data used should be mutually compatible.

pairing:

Reader and Writer

DataInputStream and DataOutputStream ... methods used should be also properly paired

ObjectInputStream and ObjectOutputStream

etc.

data compatibiliry:

byte and byte

string and string

Object and Object

etc.

I think your current code does violate these simple rules.

hiwaa at 2007-7-9 5:36:49 > top of Java-index,Archived Forums,Socket Programming...
# 6

Hey, thanks both of you, I've managed to do it.. was a little minor silly mistake as pointed different readers and writers on both sides.... :)... just a quick question not sure if you'll don't want to open up a new topic already opened up many...

If lets say on the client I have a DataInputStream that reads from teh DataouputStream on the Server side in a loop wiating for messages... Now if Lets say I send some data using the ObjectStream from the server to the client will the DataInputStream read that data or will it stay in the stream waiting for an object stream to pick it up..

Also if it waits does that mean all other messages are stuck until that is read?

Thanks

QTQa at 2007-7-9 5:36:49 > top of Java-index,Archived Forums,Socket Programming...
# 7
Okay fixed that tooo.. thanks guys :)
QTQa at 2007-7-9 5:36:49 > top of Java-index,Archived Forums,Socket Programming...
# 8

Just for the record:

> If lets say on the client I have a DataInputStream

> that reads from teh DataouputStream on the Server

> side in a loop wiating for messages... Now if Lets

> say I send some data using the ObjectStream from the

> server to the client will the DataInputStream read

> that data or will it stay in the stream waiting for

> an object stream to pick it up..

>

> Also if it waits does that mean all other messages

> are stuck until that is read?

No, it means that the input stream will misunderstand the output stream, as per the OP's original problem.

ejpa at 2007-7-9 5:36:49 > top of Java-index,Archived Forums,Socket Programming...
# 9
hehe, yeah thats what happened when i tried :(.. but it's okay i manage to implement what I had to another way..Thanks again for your help
QTQa at 2007-7-9 5:36:49 > top of Java-index,Archived Forums,Socket Programming...