• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

132
Views
C# Console Web Socket Send String to Web Application

I have created a console application as a server and also a web application as a client. I am able to sends string to from my web to my console app.

But, I have a problem to send string from my console to my web application. Refer to my code below:

Console Application (SERVER):

public class Echo : WebSocketBehavior
{
    protected override void OnMessage(MessageEventArgs e)
    {
        Console.WriteLine(e.Data);
        Send("Received: " + e.Data);
    }
}

class Program
{
    static void Main(string[] args)
    {
        WebSocketServer wsv = new WebSocketServer("ws://127.0.0.1:7890");
        wsv.AddWebSocketService<Echo>("/Echo");

        wsv.Start();

        Console.WriteLine("Server Started on ws://127.0.0.1:7890/Echo");

        Console.ReadKey();

        wsv.Stop();
    }
}

Web Application (CLIENT):

i) Model:

    public void GetRFIDPhoto()
    {
        try
        {
            wc.OnMessage += Wc_OnMessage;
            wc.Connect();
            wc.Send("RFID_Photo");
        }
        catch (Exception) { output = "No Connection Found" + Environment.NewLine; }
    }

    private void Wc_OnMessage(object sender, MessageEventArgs e)
    {
        output = e.Data;
        //received = e.Data;
    }

ii) Controller:

    public ContentResult GetRFIDPhoto()
    {
        wb.GetRFIDPhoto();
        return Content(wb.output);
    }

iii) View:

        function GetRFIDPhoto() {
        $.ajax({
            type: "GET",
            url: "/Home/GetRFIDPhoto",
            dataType: "text",
            success: function (response) {
                Output2.value = response;
            },
            failure: function (response) {
                Output2.value = response;
            },
            error: function (response) {
                Output2.value = response;
            }
        });
    }

What did I do wrong here? From Client to Server is no issue. But, I can't get the string from my Server to Client. Please help.

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error