Giter VIP home page Giter VIP logo

ldpl-net-server's Introduction

The LDPL Network Server Library

Version License Size

The LDPL Network Server Library is an library for creating socket based servers in LDPL. It aims to make it very easy to develop, test and deploy network servers, with as little work as possible. This library requires LDPL 4.3 or greater.

๐Ÿงฐ Installation

You can install this library by hand or using LPM.

๐Ÿ“ฆ Installing using LPM

Open a terminal and write lpm install ldpl_net_server. Once downloaded, include it in your LDPL project by adding the line:

using package ldpl_net_server

before the data and procedure sections of your source file. The library is ready to be used.

โœ‹๐Ÿป Installing by hand

Include the library into your LDPL project by copying the folder ldpl_net_server to your project directory and then adding the line:

include "ldpl_net_server/ldpl_net_server.ldpl"

before the data and procedure sections of your source file. The library is ready to be used.

๐Ÿ“š Documentation

This library adds five new statements to the language:

  • NET LISTEN ON <number>
    • Use this statement to start your server on port number <number>. Do this after you've written all our code and set up the whole library, as this is a locking statement and anything after it won't be executed (because your server will be too busy listening for new data and connections).
  • NET START ON <number>
    • Use this statement to start your server on port number <number> without blocking the execution of your program. You will need to use NET POLL to listen for client activity. When your program exits, the socket is closed.
  • NET POLL
    • Use this statement to listen for client activity when your server has been started using NET START ON <number>. By default the call is nonblocking and returns instantly if there is no activity, but you can set a timeout or wait forever using NET POLL FOR <number> SECONDS or NET POLL BLOCKING.
  • NET SEND <text> TO <socket number>
    • Use this statement send the message <text> to the client identified by the socket number <socket number>. The client will receive your message, easy as pie.
  • NET KICK CLIENT <socket number>
    • Use this statement to disconnect the client identified by the socket number <socket number>.

In order to work, the library requires you to declare three sub-procedures:

net_new_client

This sub-procedure will be called when a new client connects to your server. When called, it will receive three values: a socket_number identifying your client (you may want to store this value somewhere), the ip of the connecting client and its port.

sub net_new_client
    parameters:
        socket_number is number
        ip is text
        port is number
    procedure:
        # Your code goes here
end sub

net_client_left

This sub-procedure will be called when a client that was connected to our server closes the connection and disconnects. When called, it will receive three values: a socket_number identifying the client that left, the ip of the disconnecting client and its port.

sub net_client_left
    parameters:
        socket_number is number
        ip is text
        port is number
    procedure:
        # Your code goes here
end sub

net_new_message

This sub-procedure will be called whenever a connected client sends a message to our server. When called, it will receive two values: a socket_number identifying the client that sent the message and the message itself.

sub net_new_message
    parameters:
        socket_number is number
        message is text
    procedure:
        # Your code goes here
end sub

๐Ÿ“– Template

A simple template for a minimal echo server can be found in the net_template.ldpl file. Be sure to check it if you have any doubts about where to start writing your server.

๐Ÿ“œ License

This library is released under the MIT License.

ldpl-net-server's People

Contributors

lartu avatar xvxx avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ldpl-net-server's Issues

Listen should be non-blocking

Listening for connections and messages should be non-blocking so users can do stuff like, for example, poking clients.

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.