GithubHelp home page GithubHelp logo

kevind7 / bird-socket-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mateusvicente100/bird-socket-server

0.0 0.0 0.0 385 KB

This is a websocket server for Delphi.

License: MIT License

Pascal 100.00%

bird-socket-server's Introduction

Bird Socket Server

This is a websocket server for Delphi.

Delphi Supported Versions Platforms

Prerequisites

[Optional] For ease I recommend using the Boss for installation

  • Boss - Dependency Manager for Delphi

Installation using Boss (dependency manager for Delphi applications)

boss install github.com/mateusvicente100/bird-socket-server

Manual Installation

Add the following folder to your project, in Project > Options > Resource Compiler > Directories and Conditionals > Include file search path

../bird-socket-server/src

Getting Started

You need to use Bird.Socket

uses Bird.Socket;

Create an instance of TBirdSocket and assign the methods and propertys

procedure
var
  LServer: TBirdSocket;
begin
  LServer := TBirdSocket.Create(8080);
  try
    LServer.AddEventListener(TEventType.CONNECT,
      procedure(const ABird: TBirdSocketConnection)
      begin
        // Do on connect.
      end);

    LServer.AddEventListener(TEventType.EXECUTE,
      procedure(const ABird: TBirdSocketConnection)
      begin
        // Do on execute.
      end);

    LServer.AddEventListener(TEventType.DISCONNECT,
      procedure(const ABird: TBirdSocketConnection)
      begin
        // Do on disconnect.
      end);
    LServer.Start;
  finally
    LServer.DisposeOf;
  end;
end;

Samples

The bird socket can run in many Delphi way.

Console - Run a console application

ISAPI - Generate a ISAPI dll for IIS

VCL - Run a VCL application

Service - Run a windows service

Delphi Client

For Delphi websocket connections I recommend to use the bird-socket-client project. It's simple to use and install

procedure Start;
var
  LBirdSocket: TBirdSocketClient;
begin
  LBirdSocket := TBirdSocketClient.New('ws://localhost:8080');

  LBirdSocket.AddEventListener(TEventType.MESSAGE,
    procedure(const AText: string)
    begin
      Log(AText);
    end);

  LBirdSocket.Connect;
  LBirdSocket.Send('Hello Server');
end;

Web Client

For web we have native websocket connection in html

<script>
  const socket = new WebSocket('ws://localhost:8080');

  socket.addEventListener('message', function (event) {
    console.log(event.data);
  });

  socket.addEventListener('open', function (event) {
    socket.send('Hello Server!');
  });
</script>  

bird-socket-server's People

Contributors

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