Skip to content

This is a communication service and protocol separation framework, single tcp port allows a variety of communication protocols coexist, in addition to the built-in http middleware , websocket middleware, flex policy middleware and fast middleware, developers can also develop their custom middleware and installation to the communication service.

Notifications You must be signed in to change notification settings

shenzhongshan/NetworkSocket

 
 

Repository files navigation

下载当前版本(Download the latest version)

程序包管理器控制台:
PM> Install-Package NetworkSocket

项目主页和文档(Project homepage and Documentation)

非常感谢网友少林扫地僧无偿提供文档托管,项目主页和文档

服务端代码
public class HomeController : HttpController
{
    [HttpPost]
    public ActionResult Index(User user, bool fAdmin = false)
    {
        return Json(new { state = true });
    }
}

public class FastMathService : FastApiService
{
    [Api]
    public int GetSum(int x, int y, int z)
    {
        return x + y + z;
    }
}

public class WebSocketSystemService : JsonWebSocketApiService
{
    [Api]
    public UserInfo[] SearchUsers(string name)
    {
        return new UserInfo[0];
    }
}

var listener = new TcpListener();
listener.Use<HttpMiddleware>();
listener.Use<JsonWebSocketMiddleware>();
listener.Use<FastMiddleware>();            
listener.Start(1212);
客户端代码
// 浏览器请求
$.post("/home/index",{account:"admin",password:"123456",fAdmin:true});
// fastClient请求
var client = new FastTcpClient();
client.Connect(IPAddress.Loopback, 1212);
var sum = client.InvokeApi<Int32>("GetSum", 1, 2, 3).Result;
// websocket客户端请求
var ws = new jsonWebSocket('ws://127.0.0.1:1212/);
ws.invokeApi("SearchUsers", ['张三'], function (data) {
    alert(data.length == 0)
});
欢迎入群

Q群 439800853

About

This is a communication service and protocol separation framework, single tcp port allows a variety of communication protocols coexist, in addition to the built-in http middleware , websocket middleware, flex policy middleware and fast middleware, developers can also develop their custom middleware and installation to the communication service.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 93.1%
  • JavaScript 6.9%