Coder Social home page Coder Social logo

sockets's Introduction

sockets

A simple wrapper around C sockets for Carp.

Installation

(load \"https://github.com/carpentry-org/[email protected]\")

Usage

Setting up a socket can be done through setup-server and setup-client or through the macros with-server and with-client.

(let [sock (Socket.setup-server "127.0.0.1" 80)]
  ; ... work with sock
  )

(let [sock (Socket.setup-client "127.0.0.1" 80)]
  ; ...
  )

(Socket.with-server sock "127.0.0.1" 80
  ; use sock as above
  )

(Socket.with-client sock "127.0.0.1" 80
  ; use sock as above
  )

After checking that they are valid using Socket.valid?, client sockets can send and read right away, whereas server sockets have to listen and accept first. Just like in C!

Alternatively, you can also use the macro with-connection in the server, like so:

(Socket.with-server server "127.0.0.1" 80
  (Socket.with-connection &server client
    (send &client "nice to meet you!")
  )
)

If you want a server that accepts connections forever, use while-connection:

(Socket.with-server server "127.0.0.1" 80
  (Socket.while-connection &server client
    (send &client "nice to meet you!")
  )
)

This will never terminate, unless interrupted by the user or failure.


Have fun!

sockets's People

Contributors

hellerve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

timdeve

sockets's Issues

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.