A Chat Client/Server Program for C#

This is a comment thread discussing A Chat Client/Server Program for C#
  • 8 years ago
    I want to run this chat client program (TalkUser ) when I click a button on another form. How can i intergrate this chat program with that other c# program.

    Clicking a button of that programs form .... should run this "TalkUser" program.
    Pls tell me how to do it.
  • 6 years ago

    This was an excellent working example for me - showed all the major working parts in a simple and clear way.

    For those of you communicating with a Flash client you might want to use:

    SW.Write("<some message>\0");

    instead of SW.WriteLine("<some message>");

    but that's just Flash - it needs Zero terminated strings.

    Good job dude! Big Smile [:D]

  • 5 years ago
    Hi there!

    Thank you for this article. This is exactly what i need for my purposes. I've converted your server code into a Windows Service and runing it on our dedicated server. Everything works better than OK, except one frustrating thing. Both server and client when running are taking all the 100% of CPU usage. System is slowing down dramaticly and i can't release a client with a perfomance like that.

    Is there any way to speed up both client and server?

    Best regards!







  • 4 years ago
    Hi! How can I compile the client? What type of project i have to do? Windows form? Is anything missing from this article? I try to make a chat for an exercise at University. Help please!
  • 4 years ago
    A console app will be required! Nice code!! I think we use bytes instead of string we can pass images too! :-)
  • 3 years ago

    To stop the while loop lockups (100% CPU issue), you'll need to make the following changes:

    Client: while(true) { Application.DoEvents(); } Becomes: Application.Run();

    And

    Server: if(server.Pending()) { N.Sockets.TcpClient connection = server.AcceptTcpClient(); Console.WriteLine("Connection made"); BackForth BF = new BackForth(connection);
    } Becomes: N.Sockets.TcpClient connection = server.AcceptTcpClient(); Console.WriteLine("Connection made"); BackForth BF = new BackForth(connection);

    On another note, I can't find any copyright information on this. Is there any documentation on usage rights?

  • 3 years ago

    Public domain in the USA. As close as possible elsewhere (as there are countries that don't recognize public domain, apparently). Attribution welcome, but not necessary. Job offers in the Chicago area also welcome (hint hint :P ). Just to clear that up. Wouldn't have thought such a simple program would need it.

    I wrote this when I was 16 in high school so a friend and I could chat during Comp Sci class using Telnet to connect to the server on my home computer; I wrote the client program later for kicks. I'd highly recommend rewriting your own chat server from scratch; once you've done that once... IRC protocol (or at least something with multiple rooms) is not that difficult (besides server-to-server connections ;).

    For those who have used this program for class projects/homework, I would strongly suggest that you write your own chat server / client. Or even a simple web server. There are certain patterns evident in any server (ie a thread per connection, tables for usernames vs. sockets, etc). Use it as an example, don't just copy code (even though you are perfectly free to do so).

    I'm currently working on a programming language (and compiler) that is based in part on C#/Java, called Telesto at telesto.sf.net . (end plug)

  • 3 years ago

    Maybe someone on this thread can stop me from pulling the rest of my limited hair out.

    I have something running that is similar to that posted above (threads w/ TCPClient, etc) and something that should be REALLY simple is seemingly impossible. I'm attempting to display a command prompt that will have the user input directly to the right of it (easy, eh?) . The code to do this is: // Display command prompt public static void CommandPrompt(string username) { StreamWriter StrWrite; TcpClient client;

            client = (TcpClient)Server.user[username];
            StrWrite = new StreamWriter(client.GetStream());
            StrWrite.Write(">");
            StrWrite.Flush();
        }
    

    The issue is that the Flush() isn't actually causing the > to display as expected .. it will only actually display that to the client after the next WriteLine is issued OR if I terminate the > with a \r. Both things defeat the purpose since I WANT the input to be next to the >, not below it.

    Thoughts? Or am I not explaining this well?

  • 3 years ago

    Thank you for this good topic and your quidance. I have a win_app and a web-site by c# in visual studio. i want to have an online chat between win-app's users and website's visitors.(without any extra installation in visitors' computers) i want to they(user and visitor) have a private chat. Is IRC a correct way? or a best way is what?please help me.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Beware of bugs in the above code; I have only proved it correct, not tried it.” - Donald Knuth