SOCKET chat C# with private messaging

Posted by Sergei on Stack Overflow See other posts from Stack Overflow or by Sergei
Published on 2010-03-27T09:11:20Z Indexed on 2010/03/27 9:13 UTC
Read the original article Hit count: 305

Filed under:
|
|

I want to create SOCKET chat(server + clients) with private messaging. When client write smth to stream, he should notify server that it is private message for user X, how can i do this?

Actually i can do smth like this:

 string command = "PRIV|" + txtMessage.Text;
 swSender.WriteLine(command);

but i think it isn't good, for example if user wants send message like our "PRIV|" flag it will be errors

public class TestChat
{
private StreamWriter swSender;
private IPAddress ipAddr;

private void InitializeandSend()
{

    //ip from text box
    ipAddr = IPAddress.Parse(txtIp.Text);

    // Start a new TCP connections to the chat server
    tcpServer = new TcpClient();
    tcpServer.Connect(ipAddr, 1986);
    //...

    //sending message from text box
    swSender.WriteLine(txtMessage.Text);
    swSender.Flush();
}
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET