0

I am struggling to achieve the following:

  1. I have created a Java websocket server which publishes data every 1 sec.
  2. In ASP MVC projest I would like to receive the data and save them in database only so no JS involved here.

I am able to read the websocket data using console application method below :

using WebSocketSharp;

 List<string> readoutList = new List<string>();


    public void receiveMessage() {
        using (var ws = new WebSocket("ws://localhost:4567/socket/"))
        {
            ws.OnMessage += (sender, e) =>
            {
                if (e.IsText)
                {
                    readoutList.Add(e.Data.ToString());
                    Console.WriteLine(e.Data.ToString());


                }
            };


            ws.Connect();
            Console.ReadKey(true);
        }
   }` 

How to create a service of this kind within the ASP MVC project? I need some direction here.

1 Answer 1

0

MVC is stateless so you have to request back to the server to initiate the request (such as from a form post) but within the MVC controller response, you can kick off the request to the server (as an example using a different technology). The problem is there isn't necessarily a 1 to 1 translation in MVC; initiating the request using client-side JavaSvcript would be the option here. Initiating these types of requests within MVC may cause issues with timeouts too that you have to be aware of.

OR, you can consider a scheduled windows program or a windows service that is installed, which can manage itself and initiate the request every so often. I think this is the better option.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.