Giter VIP home page Giter VIP logo

jerrygaohk / networksocket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xljiulang/networksocket

0.0 2.0 0.0 11.26 MB

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.

C# 93.05% JavaScript 6.95%

networksocket's Introduction

下载当前版本(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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.