Giter VIP home page Giter VIP logo

tjsyxycommunication's Introduction

TJSYXYCommunication

a simple tcp/udp communication framework,support us to create multi-server(multi-client) with simple steps.

see more: http://www.cnblogs.com/xiaozhi_5638/p/4666957.html

  • file structure

  • manage multiple sockets in tcp server

  • manage multiple sockets in tcp client

  • manage multiple sockets in udp client

TCPServer

  • Create a server

    TCPServerManager manager = new TCPServerManager("RegisterServer");

  • Start a server

    TCPServerManager manager = new TCPServerManager("RegisterServer"); manager.Start(9090);

  • Register events

    TCPServerManager manager = new TCPServerManager("RegisterServer"); manager.TCPClientConnected += new TCPClientConnectedEventHandler(); manager.TCPClientDisConnected += new TCPClientDisConnectedEventHandler(); manager.TCPMessageReceived += new TCP MessageReceivedEventHandler();

  • Deal eessages(Event handlers)

    private void manager_TCPMessageReceived(string csID, TCPMessageRecivedEventArgs args) { //csID indicates the server which activated the event(because of multiple servers). //args.Msg indicates the Message type we received,a Msg enum type. //args.Data indicates the Message data,byte[] type. //args.Time indicates the time when we received the message. //args.End indicates the remote endpoint who sent the message, TCPEndPoint type. }

TCPCLient

  • Create a client

    TCPClientManager manager = new TCPClientManager("RegisterClient");

  • Connect the server

    TCPClientManager manager = new TCPClientManager("RegisterClient"); manager.Connect("10.0.1.10",8090); //connect to server

  • Register events

    TCPClientManager manager = new TCPClientManager("RegisterClient"); manager.TCPMessageReceived += new TCPMessageReceivedEventHandler();

  • Deal messages(Event handlers)

the same with tcp server.

UDPClient

  • Create a client

    UDPClientManager manager = new UDPClientManager("WeatherMessage");

  • Listen the port

    UDPClientManager manager = new UDPClientManager("WeatherMessage"); manager.Start(9000); //listen the 9000, receive weather message //... UDPClientManager manager = new UDPClientManager("Radar"); manager.Start(9001); //listen the 9001, receive radar data

  • Register events

    UDPClientManager manager = new UDPClientManager("WeatherMessage"); manager.UDPMessageReceived += new UDPMessageReceivedEventHandler();

  • Deal messages(Event handlers)

    private void manager_UDPMessageReceived(string csID, UDPMessageReceivedEventArgs args) { //csID indicates the client which activated the event(because of multiple clients) //args.Msg indicates th message type, Msg enum type. //args.Data indicates the message data, byte[] type. //args.Time indicates the time when we received the message. //args.RemoteIP indicates the ip who sent the message. //args.RemotePort indicates the port who sent the message. }

tjsyxycommunication's People

Watchers

 avatar  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.