Coder Social home page Coder Social logo

zig-raknet's Introduction

zig-raknet

A simple RakNet implementation in the Zig programming language.

Note

At the moment, this library only supports the master branch of Zig, meaning that it is prone to breaking changes.

Installation

The library can be installed using Zig's package manager:

zig fetch --save "https://github.com/sylvrs/zig-raknet/archive/refs/heads/master.tar.gz" 
// build.zig
pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    // add the dependency to the build script
    const network_module = b.dependency("network", .{ .target = target, .optimize = optimize }).module("network");
    const raknet_module = b.dependency("raknet", .{ .target = target, .optimize = optimize }).module("raknet");
    // ...
    // your executable should be defined already
    // i'll be using the name "exe" for the sake of this example
    exe.root_module.addImport("raknet", module);
    exe.root_module.addImport("network", network_module);
}

Usage

Example usage of the library can be found in the examples directory. Here is what a simple server looks like:

const raknet = @import("raknet");
const network = @import("network");
const std = @import("std");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    // create a server
    var server = raknet.Server.init(.{
        // the allocator to use for the server
        .allocator = gpa.allocator(),
        // the data to be sent to clients when they ping the server
        .pong_data = "Hello, World!"
        // the address to start listening on
        .endpoint = .{
            .address = .{ .ipv4 = try network.Address.IPv4.parse("0.0.0.0") },
            .port = 19132,
        },
        // whether to print messages from the server into stderr
        .verbose = true,
    });
    defer server.deinit();
    std.debug.print("Listening to data on {any}\n", .{server.address});
    // start the server and listen for incoming connections
    try server.accept();
}

zig-raknet's People

Contributors

sylvrs avatar

Stargazers

Seir avatar tetsu avatar 超神的冰凉 avatar Khang Nguyen avatar Thành Nhân avatar

Watchers

 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.