9 Replies Latest reply: Feb 12, 2007 5:06 PM by 807597 RSS

    Problem sending data over a stream

    807597
      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�hi"

      But when i send it the client recieves it as : "�� 104Q�hi", 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
        • 1. Re: Problem sending data over a stream
          807597
          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
          • 2. Re: Problem sending data over a stream
            EJP
            Don't concatenate your control bytes into the String or they will be turned into Unicode. Send them separately.
            • 3. Re: Problem sending data over a stream
              807597
              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.
              • 4. Re: Problem sending data over a stream
                EJP
                You must be writing chars and reading bytes then? or doing something else asymmetric?
                • 5. Re: Problem sending data over a stream
                  800351
                  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�hi"

                  But when i send it the client recieves it as : "��
                  104Q�hi", 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.
                  • 6. Re: Problem sending data over a stream
                    807597
                    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
                    • 7. Re: Problem sending data over a stream
                      807597
                      Okay fixed that tooo.. thanks guys :)
                      • 8. Re: Problem sending data over a stream
                        EJP
                        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.
                        • 9. Re: Problem sending data over a stream
                          807597
                          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