Sign in

    sw_socket

    A experimental *nix socket binding for MoonBit.

    socket
    network
    tcp
    udp
    moonbit
    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    416

    #📡 sw-socket: A MoonBit Socket Library

    Build Status License codecov

    sw-socket is a robust socket programming library for MoonBit applications. It provides a straightforward and efficient way to handle network communications with a clean and intuitive API.

    🚀 Key Features

    • 🔌 TCP/UDP Support – Create and manage both TCP and UDP socket connections
    • đŸ›Ąī¸ Error Handling – Comprehensive error handling for network operations
    • đŸ“Ļ Zero Dependencies – Pure MoonBit implementation with no external dependencies
    • đŸ–Ĩī¸ Unix Compatible – Designed to work on Unix-based operating systems


    #đŸ“Ĩ Installation

    moon add ShellWen/sw_socket

    #🚀 Usage Guide for sw-socket

    For usage examples, please refer to the example code in the src/example directory.


    #📜 License

    This project is licensed under the Apache-2.0 License. See LICENSE for details.

    #đŸ“ĸ Contact & Support

    👋 If you like this project, give it a ⭐! Happy coding! 🚀

    SendToAble

    trait SendToAble

    impl SendToAble for Bytes

    Sendable

    trait Sendable

    impl Sendable for Bytes

    AddrFamily

    pub(all) enum AddrFamily {
    AF_INET
    }

    Hostent

    type Hostent

    Hostent::get_addr

    fn Hostent::get_addr(self : Hostent) -> UInt

    Hostent::get_addr_str

    fn Hostent::get_addr_str(self : Hostent) -> String raise Failure

    IpProtocol

    pub(all) enum IpProtocol {
    IPPROTO_IP
    IPPROTO_TCP
    IPPROTO_UDP
    }

    SockaddrIn

    type SockaddrIn

    SockaddrIn::get_addr

    fn SockaddrIn::get_addr(self : SockaddrIn) -> UInt

    SockaddrIn::get_addr_str

    fn SockaddrIn::get_addr_str(self : SockaddrIn) -> String raise Failure

    SockaddrIn::get_family

    fn SockaddrIn::get_family(self : SockaddrIn) -> AddrFamily raise Failure

    SockaddrIn::get_port

    fn SockaddrIn::get_port(self : SockaddrIn) -> UInt16

    SockaddrIn::set_addr

    fn SockaddrIn::set_addr(self : SockaddrIn, addr : UInt) -> Unit

    SockaddrIn::set_addr_str

    fn SockaddrIn::set_addr_str(self : SockaddrIn, addr : String) -> Unit raise Failure

    SockaddrIn::set_family

    fn SockaddrIn::set_family(self : SockaddrIn, family : AddrFamily) -> Unit

    SockaddrIn::set_port

    fn SockaddrIn::set_port(self : SockaddrIn, port : UInt16) -> Unit

    Socket

    type Socket

    Socket::accept

    fn Socket::accept(self : Socket) -> (Socket, SockaddrIn) raise Failure

    Socket::bind

    fn Socket::bind(self : Socket, addr : String, port : UInt16) -> SockaddrIn raise Failure

    Socket::bind_addr

    fn Socket::bind_addr(self : Socket, addr : SockaddrIn) -> Unit raise Failure

    Socket::close

    fn Socket::close(self : Socket) -> Unit raise Failure

    Socket::connect

    fn Socket::connect(self : Socket, addr : Hostent, port : UInt16) -> SockaddrIn raise Failure

    Socket::connect_addr

    fn Socket::connect_addr(self : Socket, addr : SockaddrIn) -> Unit raise Failure

    Socket::listen

    fn Socket::listen(self : Socket, backlog : Int) -> Unit raise Failure

    Socket::recv

    fn Socket::recv(self : Socket, buf_size : Int) -> FixedArray[Byte] raise Failure

    Socket::recv_buffer

    fn Socket::recv_buffer(self : Socket, buf : FixedArray[Byte], flags? : Int) -> Int64 raise Failure

    Socket::recv_from

    fn Socket::recv_from(self : Socket, buf_size : Int) -> (FixedArray[Byte], SockaddrIn) raise Failure

    Socket::recv_from_buffer

    fn Socket::recv_from_buffer(self : Socket, buf : FixedArray[Byte], flags? : Int) -> (Int64, SockaddrIn) raise Failure

    Socket::send

    fn[Sendable : Sendable] Socket::send(self : Socket, sendable : Sendable, flags? : Int) -> Int64 raise Failure

    Socket::send_to

    fn[S : SendToAble] Socket::send_to(self : Socket, sendable : S, addr : SockaddrIn, flags? : Int) -> Int64 raise Failure

    SocketType

    pub(all) enum SocketType {
    SOCK_STREAM
    SOCK_DGRAM
    }

    get_host_by_name

    fn get_host_by_name(hostname : String) -> Hostent raise Failure

    new_sockaddr_in

    fn new_sockaddr_in() -> SockaddrIn raise Failure

    new_socket

    fn new_socket(domain : AddrFamily, type_ : SocketType, protocol? : IpProtocol?) -> Socket raise Failure

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    Š 2026 mooncakes.io