Click here to Skip to main content
15,908,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have made the server in a console application which i want to make in a winform, secondly i want to know how many clients are being connected and it is my choosing to whom i send message or i want to send message to all the clients.

please help me, actually it is my 8th day in office and they want me to test whether i can develop this or not. First is my console Server Code , following it is the code of java script client

What I have tried:

C#
class Program
    {
        static void Main(string[] args)
        {
            string url = "http://localhost:8080";
            using (WebApp.Start(url))
            {
                Console.WriteLine("Server running on {0}", url);
                Console.ReadLine();
            }
        }
    }
    class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR();
        }
    }
    public class MyHub : Hub
    {
        public void Send(string name, string message)
        {
            Clients.All.addMessage(name, message);
        }
    }

HTML
<!DOCTYPE html>
<html>
<head>
    <title>SignalR Simple Chat</title>
    <style type="text/css">
        .container {
            background-color: #99CCFF;
            border: thick solid #808080;
            padding: 20px;
            margin: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <input type="text" id="message" />
        <input type="button" id="sendmessage" value="Send" />
        <input type="hidden" id="displayname" />
        <ul id="discussion"></ul>
    </div>
    <!--Script references. -->
    
    <script src="Scripts/jquery-1.6.4.min.js"></script>
   
    <script src="Scripts/jquery.signalR-2.0.3.min.js"></script>
    
    <script src="http://localhost:8080/signalr/hubs"></script>
    
    <script type="text/javascript">
        $(function () {
            
            $.connection.hub.url = "http://localhost:8080/signalr";

           
            var chat = $.connection.myHub;

            
            chat.client.addMessage = function (name, message) {
                
                var encodedName = $('<div />').text(name).html();
                var encodedMsg = $('<div />').text(message).html();
               
                $('#discussion').append('<li>' + encodedName
                    + ':  ' + encodedMsg + '</li>');
            };
            
            $('#displayname').val(prompt('Enter your name:', ''));
            // Set initial focus to message input box.
            $('#message').focus();
            
            $.connection.hub.start().done(function () {
                $('#sendmessage').click(function () {
                  
                    chat.server.send($('#displayname').val(), $('#message').val());
                    
                    $('#message').val('').focus();
                });
            });
        });
    </script>
</body>
</html>
Posted
Updated 21-Feb-17 23:46pm
v2

1 solution

There are a number of Authored Articles[^] that can help you.

Also, the "Related Questions" sidebar on this webpage (on right) has a number of similar questions that may have the answer that you are looking for.

Lastly, there are a number of singalr step by step guide[^] that can be found with Google Search...
 
Share this answer
 
v2
Comments
Member 11866011 22-Feb-17 5:43am    
can you please provide the exact link according to my question . sorry to bother
Graeme_Grant 22-Feb-17 5:44am    
Links are provided ... look for the "^" link symbol.
Member 11866011 22-Feb-17 5:48am    
there is no exact solution to my question in those articles.
Graeme_Grant 22-Feb-17 5:50am    
"How do I send message to each client and to all clients from server using ASP.NET signalr"? I have used a couple of them myself and they helped me with the question that you have. If they are not an exact solution that you are looking for to copy, then there is more than enough information there to write your own.
Member 11866011 22-Feb-17 5:53am    
well, that was not my point. i just wanted to know some of the basic steps which i have to follow in order to achieve what i am saying.

thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900