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 6647089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:29:45+00:00 2026-05-26T00:29:45+00:00

I am creating a websocket chat application and I managed to relay chat messages

  • 0

I am creating a websocket chat application and I managed to relay chat messages to other browsers connected. I have a console application listening on one port.

My question is… If one person logs on to the system I want everybody to know that, how can I do that? I’m using Linq to map the DB but if the logging is ok how do I send that message, that user X has logged in?

FINALLY I was able to create a chatroom using websockets, here is the final product, thanks for the orientation!

http://ukchatpoint.no-ip.org/Chatpoint/Pages/Uklobby.aspx

  • 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-26T00:29:46+00:00Added an answer on May 26, 2026 at 12:29 am

    First make sure you’re sending messages as JSON (JavaScript Object Notation) as this allows structured data to be sent back and forth, and client & server can differentiate between a chat message and an instruction (e.g. someone new logged in). For instance on the client:

    mySocket.onmessage = function(event) {
        var command = JSON.parse(event.data);
    
        if(command.type === 'message') {
            var message = command.message;
            // handle chat message
        }
        else if (command.type === 'newUser') {
            var username = command.username;
            // handle new user
        }
    };
    

    On the server in ASP.NET C# you’d send them as:

    public class ChatHandler : WebSocketHandler
    {
        private JavaScriptSerializer serializer = new JavaScriptSerializer();
        private static WebSocketCollection chatapp = new WebSocketCollection();
    
        public override void OnMessage(string message)
        {
            var m = serializer.Deserialize<Message>(message);
    
            switch (m.Type)
            {
                case MessageType.NewUser:
                    chatapp.Broadcast(serializer.Serialize(new
                    {
                        type = "newUser",
                        username = m.username
                    }));
    
                    break;
                case MessageType.Message:
                    chatapp.Broadcast(serializer.Serialize(new
                    {
                        type = "message",
                        message = m.message
                    }));
    
                    break;
                default:
                    return;
            }
        }
    }
    

    As Hightechrider says, you’ll need to keep track of a list of connected clients, that’s what WebSocketCollection class does in the code listing above.

    Check out Paul Batum’s WebSocket chat example on github here (https://github.com/paulbatum/BUILD-2011-WebSocket-Chat-Samples/blob/master/BasicAspNetChat/ChatHandler.cs)

    Also he did a presentation at the recent MS BUILD conference here (http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-807T)

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

Sidebar

Related Questions

When creating a web application, and lets say you have a User object denoting
I have been working on creating an application that sends a string from an
I am creating a small application with a JavaScript client (run in the browser)
Creating a call stack diagram We have just recently been thrown into a big
Creating an Iphone application, I used to perform INSERT QUERY on different databases. But
Creating an index MySQL After I have added the FULLTEXT index, how do I
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating an XPathDocument with referenced DTD sometimes throws a web exception. Why?

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.