i have a username and password login box when i send data to the socket its fine but when i print the same data from socket then extra bit is added a head of username. why is it so...please suggest

this is very little information to go on .. can you elaborate on the matter?

What do you mean by "bit"? In computer terminology a bit is 1/8 part of a byte.

It is hard to add a bit to a String. You can only work with bytes (8 bits).

commented: good point +14

oppps i'm sorry for saying that but i mean when i send a plain string data to socket its ok and receive it in a terminal its OK the data is same as i sent to the socket but when i display the same data in the GUI there are some(especially 2) special characters are added at the beginning of string.
Example : If i send "peter" to the socket, i receive same name in the terminal but when i display the same data in GUI i got something like "xxpeter", where xx can be any character except a-z and 0-9.

Can you add some printlns to the code to show what is happening?
Print out the first two letters of the String that has the extra characters using the Integer toHexString method with the charAt(0) & charAt(1) of the String.
That will show what the 2 chars are.

Are you certain that you are using matching streams and encoding for the read and the write? Is the user name the very first thing sent over the socket?

Can i know what does stream matching mean and yes the user name is the 1st thing to be sent over the socket. But when i server send the user name list back to me it appends "ul::" in front of user names.

it appends

What is the "it"?
Your example shows 4 characters:"ul::"
Earlier you said there were two?
Also you said: xx can be any character except a-z and 0-9.
Those first two chars are in that group???

those two characters comes appended after "ul::" as ul::xxusername. I can get the clean data in terminal but not in GUI why it is so.....

ul::xxusername

Now you show that there are 6 characters added before the username. This really hard to understand. First there 2 then 4 now 6???
What are the values of the xx? Have you printed them out as I asked earlier?

You'll have to show the code that you are using. without code, there is no way to tell what is happening.
Did you add printlns to show the data when is is received and when it is moved to different destinations. If the data is received is correct, then where in the code are the extra characters added in. What classes and methods handle the data between the receive and the showing in the GUI?

those xx are randoms characters sometimes it is ! and sometimes $ , * etc

Can i know what does stream matching mean

I'm just thinking if you do something like write a String via writeUTF to a DataOutputStream, then read it in as a simple String on an InputStream the you will probably see control characters etc at the start of the input.

those two characters comes appended after "ul::" as ul::xxusername. I can get the clean data in terminal but not in GUI why it is so.....

Im confused though ... You say when you display the data in the terminal it displays correctly but not in the UI? Well i can guess either something is being done to the string by a method call that you're overlooking which i doubt, or something's going funky. Although not the best solution, if that random chars prepended to the name are... uhm lol which do i choose 2,4 or 6 ie have a pattern or set length..?:D whatever the case just substring them away? str.substring(6);

Did you ever try this:
Can you add some printlns to the code to show what is happening?
Print out the first two letters of the String that has the extra characters using the Integer toHexString method with the charAt(0) & charAt(1) of the String.
That will show what the 2 chars are.

@JamesCherrill yes i did exactly what u thought. How can i solve this?

Use the same kind of streams at both ends. To keep things as open and flexible as possible I would suggest using writeUTF/readUTF with DataOutputStream/DataInputStream. That way you can trivially extend it to send data types other than just String

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.