My server has two applications running on it:
TCP socket server that continuously accepts and sends messages to and
from clients (C# .NET Winforms)
ASP.NET application
What I need is:
When a message is received from a client via the TCP connection (app 1) I want the ASP .NET application (app 2) to reflect this data dynamically. I realise that I can set database entries via the TCP socket, which will then be picked up by the ASP.NET application.
A way of sending messages to clients from the ASP .NET application to clients that are available inside of the TCP socket server
e.g. A simple chat program where a client sends “Hi” and server responds “Welcome”. The ASP .NET should show a log of this conversation as it happens. Immediately. And if I click a button on the ASP application, it should send a message on behalf of the socket server to the client “You have been accepted onto the server”
For the most part, the messages are going to be fairly short like the ones shown here.
What is the best way to do A and B?
SignlaR is a good solution if you're getting the messages from another SignalR client (web page).
But what if these messages are being sent from a 3rd system over TCP/IP?
Then you need to open a TCP port in the ASP.NET Web Application and after receiving a message you have to push it to the web clients.
But the question is, what is the best way to have such a TCP Listener hosted in a Web Application (ASP.NET)?
if your "messages" are mostly textual, you may want to take a look at SignalR.
SignalR is a new library for asp.net to enable real-time web functionality.
It uses websockets (or long polling if websockets is unavailable at server/client).
It has support for different client types.
Related
I would like to have ASP.NET Core based website with communication to ESP32 (microcontroller with program based on Arduino code) which would have keep-alive connection. Something like serial-port without cable over network. I figured out that websocket might work and be the best solution (or not?). ESP32 doesn't support SignalR so I have to go raw websocket. I found only middle-ware solutions without support to be called from controller.
Idea is: Keep-alive connection between ESP32 and ASP.NET Core website. User can go to website and trigger action (from browser/api) which will send data to ESP32. Website is public-part. Browser and ESP32 are closed parts (I mean.. no public ip address). Also I would like to send data immediately after action is triggered. It would be nice if ESP32 would receive data within 3 seconds.
Is websocket correct idea? Can you show me or direct me how to send data from action to websocket client? I couldnt find enough informations how to make it.
Instead of Websocket I finally used TCP via TcpListener running as IHostedService. I made Singleton class with Queue to queue messages from API calls. In IHostedService while cycle I checked if there is any new queue message to send.
ESP32 connected via Wifi using WiFiClient library.
Simple & fast
I am recently learning about web sockets in .Net and have just found SignalR which seems like too good to be true in terms of the abstraction of what connection to use and it seems like there are a few signalr clients in different languages which is awesome.
In my current project different resources are being exposed through a RESTful API, and from my understanding of websockets the client needs to upgrade to a web socket connection through a HTTP request/response. Does signalR handle all this handshaking going on?
If there is an initial request/response from a GET request to retrieve a certain resource but they opt to upgrade to a socket connection, does the server give them any sort of response besides the response saying it acknowledges to open up a web socket connection or is the handshake all that occurs before the information is live updated for that particular resource?
Do you think signalR is scalable as opposed to implementing this through a protocol like STOMP where there are a large number of client libraries?
You are making things too complicated. A typical example of using signalr is:
an html file using JavaScript to connect to a signalr Server when the page is loaded. we call this signalr client.
a signalr server written in c#. it can be a winform or console or service.
the signalr Server can call any dll, or webservices or webapi located in the same server, or even in different Server.
then, the client can call any function defined in the signalr server. the server can call any function defined in the client for a particular client or for groups of clients.
also, client x can call client y functions as well.
you can actually forget about Web sockets, signalr choose the most appropriate transport protocol for you. it will choose Web sockets if it is available in both the server and the client.
I have several clients connected to a server using TCP. Because of some problems with the TCP (or the IT policies) I want to change the protocol to TCP using either web service or web API
The problem is that the HTTP is a request from client to server, but not the other way around
I want to create this option where the server can push responses to the client
Server:
.NET windows application with TCP connections, hold few clients each client has a logic instance
Client:
.net windows application with TCP connection
Because of the server architecture I don't want to use ASP.NET or other application rely on IIS.
Does WCF can provide me with this solution?
We use SignalR in one of our projects
NuGet package
Video Tutorial
IIS is not necessary, you can self-host this service (as we just do)
I have a client mobile app that needs to listen for updates from the server. But the server send the message oly to one client at once (it is not a broadcasting). How can I kep track of whom to send the message to, and send it using sockets?
should the mobile app be the server for the socket, or the asp.net server?
The mobile app should be a client. It should have unique ID (a GUID works well). The server accepts a connection from the mobile app. The mobile app then sends its unique ID, the server creates a object that stores the socket and unique ID. If 10 clients connect, you store 10 sockets each with there own unqiue ID.
Now the server has an update to push out:
Loop through your objects, sending data down each socket to the mobile apps.
p.s I do not think asp.net would work for this. But you could easily code a C# .NET app.
EDIT:
Additionally, if you were to self-host an WCF service in the C# .NET app, then you could consume the service from the ASP.NET web application. Then, this would allow you to send data from the web application to the C# app and the C# app could pass that data down to the sockets, or trigger the c# app to send certain data down the sockets to the mobile apps.
We want to implement a client server application. here is the scenario.
Server listens for client 24/7.
Server accept request for client and save it in DB for further process.
Once processing is done (it may take few hours), Server will response back to client.
in short , client and server listens for each other 24/7.
I want to implement it in C# but i also want that it should be accessibly from all platforms.
Also is it possible in WCF?
I agree with Yuck, this is a basic WCF scenario. There a few articles, videos and tutorials to get you started here http://msdn.microsoft.com/en-us/netframework/dd939784