# posix-socket-messaging

> Simple messaging protocol for the posix-socket module

Latest version **0.0.1** (published 2021-04-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install posix-socket-messaging
pnpm add posix-socket-messaging
yarn add posix-socket-messaging
bun add posix-socket-messaging
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2021-04-19 |
| First published | 2021-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Laurent Christophe |
| Maintainers | lachrist |
| Keywords | Node, Posix, Socket, Synchronous, Messaging, Communication |

## Links

- npm: https://www.npmjs.com/package/posix-socket-messaging
- Repository: https://github.com/lachrist/posix-socket-messaging
- Homepage: https://github.com/lachrist/posix-socket-messaging#readme
- Issues: https://github.com/lachrist/posix-socket-messaging/issues
- npm.io page: https://npm.io/package/posix-socket-messaging

## Dependencies (1)

- [posix-socket](https://npm.io/package/posix-socket.md) ^1.0.1

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2021-04-19
- 0.0.0 — 2021-04-12

## README

# posix-socket-messaging

This module implements the same simple messaging protocol as [net-socket-messaging](https://github.com/lachrist/net-socket-messagin) but in a *synchronous* manner on top of [posix-socket](https://github.com/lachrist/posix-socket).

**Disclaimer** Doing synchronous stuff in JavaScript is bad and you should not do it.
That being said, if you *are* going to do synchronous communication anyway you might as well do it efficiently and avoid the horrendous performance overhead of the synchronous functionalities of `child_process` and `fs`.

## Example

```js
const PosixSocket = require("posix-socket");
const {send, receive} = require("posix-socket-messaging");
const sockfd = PosixSocket.socket(PosixSocket.AF_INET6, PosixSocket.SOCK_STREAM, 0);
PosixSocket.connect(sockfd, {
  sin6_family: PosixSocket.AF_INET6,
  sin6_port: 8080,
  sin6_flowinfo: 0,
  sin6_addr: "::1",
  sin6_scope_id: 0
});
send(sockfd, "foo");
console.log(receive(sockfd));
PosixSocket.close(sockfd);
```

## API

### `send(sockfd, message)`

*Synchronously* send a message.

* `sockfd` `<integer>`: the file descriptor of the socket.
* `message` `<string>`: the message to send which cannot be longer than `256 * 2^20` characters.

### `message = receive(sockfd)`

*Synchronously* receive a message.

**Yes, this will block the entire node process up until you completely receive a message**.

* `sockfd` `<integer>`: the file descriptor of the socket.
* `message` `<string>`: the received message.

---
_Source: https://npm.io/package/posix-socket-messaging · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
