Line break problem

N

Nurchi BECHED

Hello, my dearest respected brother, All!

I am writing a simple p2p messenger (like Net Meeting)
It is working fine except for it is not braking line properly.
The following is a block of code that receives a message
on the server:
if
((this.server!=null)&&this.server.ServerStarted&&this.server.HasConnection)
{
this.server.ReceiveMessage();
this.tbMessageIn.Text+=
this.server.Message+
" Hello world\r\n ";
}

It is only adding 'this.server.Message' and forgetting about the other part
of the string.
If I remove 'this.server.Message' it works just fine, but doesn't show the
message received
from client.

However, the following works for outgoing messages:
if ((this.server!=null)&&
this.server.ServerStarted&&
this.server.HasConnection)
if
(this.server.SendMessage(this.tbMessageOut.Text+"\r\n")==StaticVariables.OK)
{
this.statusBar1.Text="Message has been successfully sent!";
this.tbMessageOut.Text="";
}
else
this.statusBar1.Text="An error occured, message was not sent!";

But this is not a solution to my problem, why does it not work on incoming
messages.

BTW, 'this.server.Message' is a property which is defined as follows:
public string Message
{
get
{
return this.message;
}
}

Where 'return this.message' is a local (for the server class) private string
variable

Thanks you.
With best regards, Nurchi BECHED.
 
J

Jon Skeet [C# MVP]

Nurchi BECHED said:
Hello, my dearest respected brother, All!

I am writing a simple p2p messenger (like Net Meeting)
It is working fine except for it is not braking line properly.
The following is a block of code that receives a message
on the server:
if
((this.server!=null)&&this.server.ServerStarted&&this.server.HasConnection)
{
this.server.ReceiveMessage();
this.tbMessageIn.Text+=
this.server.Message+
" Hello world\r\n ";
}

It is only adding 'this.server.Message' and forgetting about the other part
of the string.

I suggest you have a look at whether this.server.Message has any null
characters (unicode 0) at the end - if it has, you may want to have a
look at the ReceiveMessage method to find out why. I believe text boxes
"stop" when they encounter null characters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top