• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

131
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda