Community discussion forum

A Chat Client/Server Program for C#

This is a comment thread discussing A Chat Client/Server Program for C#
  • 10 years ago

    This thread is for discussions of A Chat Client/Server Program for C#.

  • 4 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.
  • 3 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]

  • 2 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!







  • 11 months 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!
  • 9 months ago
    A console app will be required! Nice code!! I think we use bytes instead of string we can pass images too! :-)
  • 3 months 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 months 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 months 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?

Post a reply

Enter your message below

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

We'd love to hear what you think! Submit ideas or give us feedback