Skip to content

Commit

Permalink
Initial spec for TCP
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Jun 12, 2013
1 parent 0570c1b commit 9e2114d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions specs/tcp.md
@@ -0,0 +1,44 @@
# TCP

This interface describes the TCP client and server interface used in the js-git project.

Streams are in [min-stream][] format.

## createServer(port, [host]) -> stream

Create a TCP server listening on `port` and `host` (defaulting to localhost). The stream is a connection stream. It emits an event every time a new client connects.

The connection events in the stream are objects that contain a socket source and sink representing the duplex TCP socket.

```js
var server = tcp.createServer(8080);
// Get the first client and make them talk to themselves.
server(null, function (err, client) {
if (err) throw err;
client.sink(client.source);

// Then close the server to disallow more connections
server(true, function (err) {
if (err) throw err;
console.log("Server closed");
});
});
```

## connect(port, [host]) -> socket

Connect to a TCP server on `port` and `host` (defaulting to localhost).

Returns a socket object containing source and sink min-streams representing the duplex socket.

```js
var socket = tcp.connect(8080);
// Make the server talk to itself
socket.sink(socket.source);
```

# Concrete Implementations

- [min-stream-node/tcp.js](https://github.com/creationix/min-stream-node/blob/master/tcp.js)

[min-stream]: https://github.com/creationix/min-stream#the-interface

0 comments on commit 9e2114d

Please sign in to comment.