Chat Bot in C# using TcpClient working partially

So, I have code that connects to successfully (ie. It connects, receives connection confirmation), then sends authentication data (sends “USER…”, “PASS…”, “NICK”… and receives the “maze” message), then joins channel (and receives user list). It even receives “PING” messages.

However, for life of me, I cannot get it to read messages typed in via the chat (at the website).

Here is the code that I’m using:

TcpClient clientSocket = new TcpClient();
.... Connection code -- all good

var stream = clientSocket.GetStream();
.... Authentication code -- all good
.... Join channel code -- all good

bool done = false;
    string str = "";
    byte[] buffer = new byte[1024];
    int bytesRead = 0;
    int readingPosition = 0;
        bytesRead = stream.Read(buffer, readingPosition , buffer.Length);
        readingPosition += bytesRead;
        str += Encoding.UTF8.GetString(buffer, 0, bytesRead);
    ..... other code, including stream and connection closing omitted for brevity.

The stream reading code, does not return anything when text is being typed in the “Joined” to channel. The only strings that ever get returned are the "PING"s from the sever.

Any suggestions?

Make sure you use all lowercase characters for the channel in your JOIN i.e. “JOIN #3ventic” instead of “JOIN #3Ventic”.

The code you’ve shown seems like it would work fine (and you said you were receiving PINGs so it seems like it is?)

the strings I’m providing are already lower case, so there’s got to be something else. The point of failure is the fact that no text typed form the channel joined is making it to the client I created. But any massage sent by the server is.

Also, I have some Python code that does the same thing (action by action) and that is working fine. So, perhaps servers are allergic to .net code based calls? (I’m kidding, but maybe I’m not…)

what channel? It might be on eventchat

Channel is backseatgamez

Eventchat? I’m not sure what eventchat is.

If your Python code works for the same channel, then the problem is most likely in the steps leading up to your while loop (since you say you receive PINGs fine).

Silly mistake. I forgot to add the “#” right before the channel name when creating the join channel command.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.