Cyaim.WebSocketServer provides multi-language client SDKs that support automatic endpoint discovery and interface contract-based calling.
- Package:
Cyaim.WebSocketServer.Client - Target Frameworks: .NET 8.0, 9.0, 10.0
- Features:
- Dynamic proxy using
DispatchProxy [WebSocketEndpoint]attribute support- Lazy loading and custom options
- Dynamic proxy using
- Location:
Clients/Cyaim.WebSocketServer.Client/ - Documentation: README.md
- Package:
@cyaim/websocket-client - Features:
- Full TypeScript support
- Decorator support for endpoint specification
- Based on
wslibrary
- Location:
Clients/cyaim-websocket-client-js/ - Documentation: README.md
- Package:
cyaim-websocket-client - Features:
- Based on
tokio-tungstenite - Async support
- Type safety
- Based on
- Location:
Clients/cyaim-websocket-client-rs/ - Documentation: README.md
- Package:
com.cyaim:websocket-client - Features:
- Maven support
- Based on
Java-WebSocket - Java 11+ support
- Location:
Clients/cyaim-websocket-client-java/ - Documentation: README.md
- Package:
cyaim_websocket_client - Features:
- Flutter/Dart support
- Based on
web_socket_channel - Async support
- Location:
Clients/cyaim-websocket-client-dart/ - Documentation: README.md
- Package:
cyaim-websocket-client - Features:
- Based on
websocketsandaiohttp - Async support (asyncio)
- Python 3.8+
- Based on
- Location:
Clients/cyaim-websocket-client-python/ - Documentation: README.md
All client SDKs implement the following core features:
Clients automatically fetch available endpoints from the server's /ws_server/api/endpoints API:
{
"success": true,
"data": [
{
"controller": "WeatherForecast",
"action": "Get",
"methodPath": "weatherforecast.get",
"methods": ["GET"],
"fullName": "WeatherForecast.Get",
"target": "weatherforecast.get"
}
]
}Define interfaces/types and call methods directly, without manually constructing requests:
C# Example:
public interface IWeatherService
{
Task<WeatherForecast[]> GetForecastsAsync();
Task<WeatherForecast> GetForecastAsync(string city);
}
var factory = new WebSocketClientFactory("http://localhost:5000", "/ws");
var client = await factory.CreateClientAsync<IWeatherService>();
var forecasts = await client.GetForecastsAsync();TypeScript Example:
interface IWeatherService {
getForecasts(): Promise<WeatherForecast[]>;
getForecast(city: string): Promise<WeatherForecast>;
}
const factory = new WebSocketClientFactory('http://localhost:5000', '/ws');
const client = await factory.createClient<IWeatherService>({
getForecasts: async () => {},
getForecast: async (city: string) => {}
});
const forecasts = await client.getForecasts();All clients provide strong typing for requests and responses:
- Compile-time type checking (where supported)
- Runtime type validation
- Automatic serialization/deserialization
All clients support flexible configuration options:
- Lazy Loading: Load endpoints on-demand instead of upfront
- Validation: Optional validation of all methods have corresponding endpoints
- Error Handling: Configurable error handling behavior
using Cyaim.WebSocketServer.Client;
var factory = new WebSocketClientFactory("http://localhost:5000", "/ws");
var client = await factory.CreateClientAsync<IWeatherService>();
var forecasts = await client.GetForecastsAsync();import { WebSocketClientFactory } from '@cyaim/websocket-client';
const factory = new WebSocketClientFactory('http://localhost:5000', '/ws');
const client = await factory.createClient<IWeatherService>({
getForecasts: async () => {}
});
const forecasts = await client.getForecasts();use cyaim_websocket_client::WebSocketClientFactory;
let mut factory = WebSocketClientFactory::new(
"http://localhost:5000".to_string(),
"/ws".to_string(),
None,
);
let client = factory.create_client();
let forecasts: Vec<WeatherForecast> = client
.send_request("weatherforecast.get", None::<()>)
.await?;import com.cyaim.websocket.*;
WebSocketClientFactory factory = new WebSocketClientFactory(
"http://localhost:5000", "/ws", new WebSocketClientOptions());
WebSocketClient client = factory.createClient();
client.connect().get();
List<WeatherForecast> forecasts = client.sendRequest(
"weatherforecast.get", null, new TypeToken<List<WeatherForecast>>(){}.getType()
).get();import 'package:cyaim_websocket_client/cyaim_websocket_client.dart';
final factory = WebSocketClientFactory('http://localhost:5000', '/ws');
final client = factory.createClient();
await client.connect();
final forecasts = await client.sendRequest<List<Map<String, dynamic>>>(
'weatherforecast.get',
);from cyaim_websocket_client import WebSocketClientFactory
factory = WebSocketClientFactory('http://localhost:5000', '/ws')
client = factory.create_client()
await client.connect()
forecasts = await client.send_request('weatherforecast.get')All clients require the server to provide the following API endpoint:
- GET
/ws_server/api/endpoints- Returns all available WebSocket endpoints
This endpoint is automatically provided by the Dashboard module. Make sure the Dashboard is configured in your server:
builder.Services.AddWebSocketDashboard();
app.UseWebSocketDashboard("/dashboard");If method names don't match server endpoints, you can specify custom mappings:
C#:
public interface IUserService
{
[WebSocketEndpoint("user.getbyid")]
Task<User> GetUserByIdAsync(int id);
}TypeScript:
import { endpoint } from '@cyaim/websocket-client';
const client = await factory.createClient<IUserService>({
[endpoint('user.getbyid')]: async (id: number) => {}
});Load endpoints only when needed:
C#:
var options = new WebSocketClientOptions
{
LazyLoadEndpoints = true
};
var factory = new WebSocketClientFactory("http://localhost:5000", "/ws", options);TypeScript:
const options = new WebSocketClientOptions();
options.lazyLoadEndpoints = true;
const factory = new WebSocketClientFactory('http://localhost:5000', '/ws', options);- Define Minimal Interfaces: Only define the methods you need, not all available endpoints
- Use Type Safety: Leverage your language's type system for compile-time safety
- Handle Errors: Always handle potential errors from WebSocket operations
- Connection Management: Let the client manage connections automatically
- Endpoint Caching: Clients cache endpoints by default for better performance
If you get an "endpoint not found" error:
- Check that the server is running and accessible
- Verify the Dashboard API is enabled (
/ws_server/api/endpoints) - Use
[WebSocketEndpoint]attribute or decorator to specify the exact endpoint target - Check method name matches server action name (case-insensitive)
If you have connection problems:
- Verify the server URL and channel path are correct
- Check firewall and network settings
- Ensure WebSocket is enabled on the server
- Check server logs for errors
- Core Library - Server-side implementation
- Dashboard - Dashboard and API endpoints
- Quick Start - Getting started guide
All client SDKs are licensed under MIT License.
Copyright © Cyaim Studio