Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
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.

over 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Asistente virtual