Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6827821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:18:37+00:00 2026-05-26T22:18:37+00:00

For a school assignment we have to make a client server chat program in

  • 0

For a school assignment we have to make a client server chat program in C#. I have never done any networking in the past before so its very confusing for me. I read a book on C# networking, and I was able to make a very basic chat that works using binary readers and writers and a TCP socket. However for the assignment I have to make the client list all connected users. Now, how would I make it so that the client only reads the stream for a list when someone disconnects or connects on the server. I could make it so that the clients is always downloading a new list, but I feel that’s a lot of redundant data being sent.

On a side note, I’m confused with how the client/server knows what the data in the stream is. So far I only have a string being sent through the stream which represents a message. Is there a way to attach some sort of signature or something to the data being sent so that the server or client knows that that specific data is the username or perhaps a message to be displayed.

Edit:
I’m having issues with the stream. I have a method that’s running in its own thread that’s always checking for information being sent. Its listing for both a string that’s a message to display message and a List containing users connected. The problem is that the order of the data being sent isn’t always in a consistent order. Sometimes the message is first, others the list is, and sometimes its only a message in the stream. Is there a way to tell what data is being read? Here is my client side listener.

private void incoming()
    {
        while (true)
        {
            try
            {
                string read = reader.ReadString();
                if (read.Length > 0)
                    lbOutput.Items.Add(read);
                    lbUsers.Items.Clear();

                List<string> users = (List<string>)binaryFormatter.Deserialize(stream);
                foreach (string user in users)
                    lbUsers.Items.Add(user.ToString());
            }
            catch { lbOutput.Items.Add("Error reading the stream"); }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:18:38+00:00Added an answer on May 26, 2026 at 10:18 pm

    When a new client connects, it should send a message to the server to inform it that it has connected and ask it to store its name. Then the server can broadcast a message to all other clients with the new list (or just the name of the new client). Rough outline:

    public class Server {
    
         public void StartAcceptingConnections() {
    
              while(true) {
                  // accept socket connection
                  // read new user name
                  foreach(Client cl in connectedClients) {
                      // send new user name to cl.Socket
                  }    
              }             
         }
    }
    

    In parallel, you are receiving messages from clients to be routed (I assume). When a client leaves, it will again send a disconnect message and the server can broadcast the change to the rest of the clients.

    If you want to work with more than just bytes and strings, you can try to send entire object by serialization. Have a look at this tutorial: http://msdn.microsoft.com/en-us/magazine/cc301761.aspx.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For an assignment at school, we have to use structs to make matrices that
I am creating a file server application for school assignment. What I currently have
For a school assignment, we have to make a Usecase diagram. But the documentation
I'm coding an XML viewer for a school assignment but I don't have any
For a school assignment I have to write x86 assembly code, except I can't
I currently have a school assignment that involves both PHP and asp.net. Now the
For a database assignment I have to model a system for a school. Part
This is a school assignment and I have most of it under control, but
I am doing an assignment for school where we are to make two php
I'm writing a simple booking program for a car rental (a school assignment). Me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.