Skip to content

An event-oriented protocol aggregator (tcp/WebSocket)

License

Notifications You must be signed in to change notification settings

Folleach/SocketFlow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SocketFlow

An event-oriented protocol aggregator (tcp/WebSocket)
Light and simple for use

Supported languages

client server
C# client server
Js client -
Java - -

Getting started

Server

var server = new FlowServer(FlowOptions.Lazy);            // Lazy - auto use unknown types as json
server.UsingModule(new TcpModule(IPAddress.Any, 3333));   // To connect via TCP
server.UsingModule(new WebSocketModule("0.0.0.0:3334"));  // To connect via WebSocket (From browser)
server.UsingWrapper(new Utf8DataWrapper());               // To use String as value for transfer

server.Bind<string>(1, (client, value) => {         // Bind handler for id 1.
    Console.WriteLine($"User message: {value}");    // When client send message as string with id 1
});                                                 // server print this message to console.

server.ClientConnected += destinationClient => {    // Subscribe to client connect.
    destinationClient.Send(1, "Hello! I'm server"); // When client was be connect, send message for him.
};                                                  // Pay attention. Id from client to server and id from
                                                    // server to client may be equals. It's not a problem.

server.Start();

Client

C# client works only via TCP

var client = new FlowClient(IPAddress.Parse("127.0.0.1"), 3333, FlowOptions.Lazy);
client.UsingWrapper(new Utf8DataWrapper());

client.Bind<string>(1, value => {
    Console.WriteLine($"Server say: {value}");
});

client.Connect();

client.Send(1, "Hello server. I am connect to you to receive realtime values");

Protocol

  • Have a simple overhead (8 bytes for every event)
  • Ability to transfer 2 GB of event (2147483639 bytes)
  • Ability to use your data structure (Named DataWrapper)
    such as:
    • Json
    • Xml
    • Raw bytes
    • Your own structure
  • May be created 2 billion different events

Every event looks as:

length type event data
bytes: 0 1 2 3 4 5 6 7 8 9 10 11 12 ...

First 4 bytes (int) it is length of data, no more.
Second 4 bytes (int) it is type of event, determines which event occurred.
Then followed by data, which will be converted to value using the data wrapper.

About

An event-oriented protocol aggregator (tcp/WebSocket)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages