Giter Site home page Giter Site logo

kgnetsocket's Introduction

##使用方法

1.网络消息自定义类

都必须继承KGNetData 然后打上可序列化标签[Serializable]

[Serializable]
public class NetData : KGNetData {
    public string dataname;
}

2.创建客户端/服务器端

 //  KGSocketClient<KGNetSession<KGNetData>, KGNetData> kg =    new KGSocketClient<KGNetSession<NetData>, NetData>();
            KGSocketServe<KGNetSession<KGNetData>, KGNetData> kg=    new KGSocketServe<KGNetSession<NetData>,NetData>();

       //都是调用这个创建
            kg.StartCreate("127.0.0.1", 8897);

3.发送数据

就是调用KGNetSession里面的SendData(T)

kg.Client.SendData(new KGNetData { dataname = "123456" });

4.接收网络消息

这里留了一个回调事件和回调函数OnReciveDataEvent/OnReciveData

重写OnReciveData 就好了 如果别的要加事件可以往OnReciveDataEvent加

 protected override void OnReciveData(T data)
        {
            OnReciveDataEvent?.Invoke(data);
            ("接收到了一条消息:"+data).KLog();
        }

5.打印数据的

在KGBaseNet里面的 这里是给 在另外一些 Console.WriteLine打印不了留出来用的


        public void SetLog(Action<string, LogLevel> LogEvent,bool run=true)
        {
            LogEvent.SetLog(run);
        }

kgnetsocket's People

Contributors

lkaiguo avatar

Watchers

James Cloos avatar

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.