Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xljiulang/NetworkSocket
NetworkSocket是一个以中间件(middleware)扩展通讯协议,以插件(plug)扩展服务器功能的支持SSL安全传输的通讯框架;目前支持http、websocket、fast、flex策略与silverlight策略协议。
https://github.com/xljiulang/NetworkSocket
client server socket tcp
Last synced: 2 months ago
JSON representation
NetworkSocket是一个以中间件(middleware)扩展通讯协议,以插件(plug)扩展服务器功能的支持SSL安全传输的通讯框架;目前支持http、websocket、fast、flex策略与silverlight策略协议。
- Host: GitHub
- URL: https://github.com/xljiulang/NetworkSocket
- Owner: xljiulang
- Archived: true
- Created: 2014-12-05T06:22:06.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-03T16:02:28.000Z (almost 7 years ago)
- Last Synced: 2024-11-07T21:20:15.406Z (3 months ago)
- Topics: client, server, socket, tcp
- Language: C#
- Homepage:
- Size: 12 MB
- Stars: 458
- Watchers: 70
- Forks: 223
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
##### 下载当前版本(Download the latest version)
程序包管理器控制台:
PM> `Install-Package NetworkSocket`##### 服务端代码
```c#
public class HomeController : HttpController
{
[HttpGet]
public UserInfo[] GetUsers(string name)
{
return new UserInfo[0];
}
[HttpGet]
public async Task AboutAsync(string name)
{
await Task.Delay(TimeSpan.FromSeconds(1));
return "Http";
}
}public class FastService : FastApiService
{
[Api]
public UserInfo[] UserInfo(string name)
{
return new UserInfo[0];
}
[Api]
public async Task AboutAsync(string name)
{
await Task.Delay(TimeSpan.FromSeconds(1));
return "Fast";
}
}public class JsonWebSocketService : JsonWebSocketApiService
{
[Api]
public UserInfo[] GetUsers(string name)
{
return new UserInfo[0];
}
[Api]
public async Task AboutAsync(string name)
{
await Task.Delay(TimeSpan.FromSeconds(1));
return "WebSocket";
}
}var listener = new TcpListener();
listener.Use();
listener.Use();
listener.Use();
listener.Start(1212);
```##### 客户端代码
```c#
// http js请求
$.getJSON("/Home/GetUsers",{name:"admin"},function(data){
alert(data.length == 0)
});
$.getJSON("/Home/About",{},function(data){
alert(data == "Http")
});// fastClient请求
var client = new FastTcpClient();
client.Connect(IPAddress.Loopback, 1212);
var users = await client.InvokeApi("GetUsers", "admin");
var about = await client.InvokeApi("About"); // about == "Fast"// websocket js请求
var ws = new jsonWebSocket('ws://127.0.0.1:1212/);
ws.invokeApi("GetUsers", ['admin'], function (data) {
alert(data.length == 0)
});
ws.invokeApi("About", [], function (data) {
alert(data == "WebSocket")
});// websocketClient请求
var client = new JsonWebSocketClient();
await client.ConnectAsync(IPAddress.Loopback, 1212);
var users = await client.InvokeApi("GetUsers", "admin");
var about = await client.InvokeApi("About"); // about == "WebSocket"
```##### Async Void支持
FilterAttributer提供void OnXXX(ActionContext filterContext)的重写方法,当重写为
`async` void OnXXX(ActionContext filterContext)之后,不影响Filter的等待流程,但是执行线程不是在异步等待执行,
而是转为同步等待执行。
##### 欢迎入群
Q群 439800853