ASP.NET Core SignalR के लिए एक Flutter क्लाइंट। क्लाइंट सर्वर-साइड हब फ़ंक्शन को बुलाने और सर्वर द्वारा जारी किए गए तरीकों के कॉल को प्राप्त करने में सक्षम है।
सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
ASP.NET Core SignalR के लिए एक Flutter क्लाइंट, जो Flutter ऐप्स और .NET Core बैकएंड के बीच रियल-टाइम संचार की अनुमति देता है। यह सर्वर-साइड हब मेथड को कॉल करने और सर्वर से मेथड कॉल प्राप्त करने का समर्थन करता है, जिससे यह लाइव अपडेट, चैट ऐप्स और सहयोगी टूल्स के लिए आदर्श है। पैकेज Android, iOS, macOS, Windows और Linux पर काम करता है, जिससे व्यापक प्लेटफॉर्म संगतता सुनिश्चित होती है। SignalR प्रोटोकॉल पर निर्मित, यह प्रभावी, कम लेटेंसी वाले संदेश प्रेषण के साथ स्वचालित पुनर्संबंध और फॉलबैक तंत्र प्रदान करता है।
उपयोग
रियल-टाइम चैट एप्लिकेशन्स
लाइव डेटा डैशबोर्ड
सहयोगात्मक संपादन उपकरण
आईओटी डिवाइस मॉनिटरिंग
पुश नोटिफिकेशन्स
मुख्य विशेषताएँ
द्विदिश संचार
स्वचालित पुनर्संबंध
प्लेटफॉर्म के अनुकूल समर्थन
सर्वर पद्धति आह्वान
क्लाइंट इवेंट हैंडलिंग
इनके लिए उपयुक्त
रियल-टाइम ऐप डेवलपर्स
बैकएंड-इंटीग्रेटेड फ्लटर प्रोजेक्ट्स
लाइव अपडेट की आवश्यकता वाले एप्लिकेशन
ASP.NET Core SignalR का उपयोग करने वाली टीमें
कम लेटेंसी संचार की आवश्यकता है
विचार योग्य बातें
एक संगत ASP.NET Core SignalR सर्वर की आवश्यकता होती है
नेटवर्क स्थिरता प्रदर्शन को प्रभावित करती है
सुरक्षित हब्स के लिए प्रमाणीकरण सेटअप की आवश्यकता है
मूल लाइब्रेरी की तुलना में सीमित डॉक्यूमेंटेशन
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
signalr_client
A Flutter SignalR Client for ASP.NET Core.
ASP.NET Core SignalR is an open-source library that simplifies adding real-time web functionality to apps. Real-time web functionality enables server-side code to push content to clients instantly.
Tested with ASP.NET Core 3.1 & ASP .NET Core 6
The client is able to invoke server side hub functions (including streaming functions) and to receive method invocations issued by the server. It also supports the auto-reconnect feature.
The client supports the following transport protocols:
Important Note: if you are experiencing issues (for example not receiving message callback) with the latest version, please give a try to older version as signalr_netcore: 0.1.7+2-nullsafety.3 but bear in mind that this version does not support auto reconnect functionalities and need to be handled manually.
Usage
Let's demo some basic usages:
1. Create a hub connection:
// Import the library.import'package:signalr_netcore/signalr_client.dart';
// The location of the SignalR Server.final serverUrl = "192.168.10.50:51001";
// Creates the connection by using the HubConnectionBuilder.final hubConnection = HubConnectionBuilder().withUrl(serverUrl).build();
// When the connection is closed, print out a message to the console.final hubConnection.onclose( (error) => print("Connection Closed"));
// Import theses libraries.import'package:logging/logging.dart';
import'package:signalr_netcore/signalr_client.dart';
// Configer the loggingLogger.root.level = Level.ALL;
// Writes the log messages to the consoleLogger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name}: ${rec.time}: ${rec.message}');
});
// If you want only to log out the message for the higer level hub protocol:final hubProtLogger = Logger("SignalR - hub");
// If youn want to also to log out transport messages:final transportProtLogger = Logger("SignalR - transport");
// The location of the SignalR Server.final serverUrl = "192.168.10.50:51001";
final connectionOptions = HttpConnectionOptionsfinal httpOptions = newHttpConnectionOptions(logger: transportProtLogger);
//final httpOptions = new HttpConnectionOptions(logger: transportProtLogger, transport: HttpTransportType.WebSockets); // default transport type.//final httpOptions = new HttpConnectionOptions(logger: transportProtLogger, transport: HttpTransportType.ServerSentEvents);//final httpOptions = new HttpConnectionOptions(logger: transportProtLogger, transport: HttpTransportType.LongPolling);// If you need to authorize the Hub connection than provide a an async callback function that returns // the token string (see AccessTokenFactory typdef) and assigned it to the accessTokenFactory parameter:// final httpOptions = new HttpConnectionOptions( .... accessTokenFactory: () async => await getAccessToken() ); // Creates the connection by using the HubConnectionBuilder.final hubConnection = HubConnectionBuilder().withUrl(serverUrl, options: httpOptions).configureLogging(hubProtLogger).build();
// When the connection is closed, print out a message to the console.final hubConnection.onclose( (error) => print("Connection Closed"));
2. Connect to a Hub:
Calling following method starts handshaking and connects the client to SignalR server
final result = await hubConnection.invoke("MethodOneSimpleParameterSimpleReturnValue", args: <Object>["ParameterValue"]);
logger.log(LogLevel.Information, "Result: '$result");
4. Calling a client function:
Assuming the server calls a function "aClientProvidedFunction":
hubConnection.on("aClientProvidedFunction", _handleAClientProvidedFunction);
// To unregister the function use:// a) to unregister a specific implementation:// hubConnection.off("aClientProvidedFunction", method: _handleServerInvokeMethodNoParametersNoReturnValue);// b) to unregister all implementations:// hubConnection.off("aClientProvidedFunction");
...
void_handleAClientProvidedFunction(List<Object> parameters) {
logger.log(LogLevel.Information, "Server invoked the method");
}
5. Using Msgpack for serialization
The Hub should be configured to use the msgpack protocol in both the client and server
Client
import'package:signalr_netcore/msgpack_hub_protocol.dart';
_hubConnection = HubConnectionBuilder()
.withUrl(_serverUrl, options: httpOptions)
/* Configure the Hub with msgpack protocol */
.withHubProtocol(MessagePackHubProtocol())
.withAutomaticReconnect()
.configureLogging(logger)
.build();
Server
Add the following packge to your ASP NET core project
Microsoft.AspNetCore.SignalR.Protocols.MessagePack
public void ConfigureServices(IServiceCollection services)
{
// Configure the hub to use msgpack protocol
services.AddSignalR().AddMessagePackProtocol();
}
A note about the parameter types
All function parameters and return values are serialized/deserialized into/from JSON by using the dart:convert package (json.endcode/json.decode). Make sure that you:
use only simple parameter types
or
use objects that implements toJson() since that method is used by the dart:convert package to serialize an object.