<commit_before># clj-tcp

A fast async tcp client library built on netty.

There are many good async http libraries out there, but no lowlevel tcp library that allows you to build your own protocols on top of it.
This library aims to provide this, you send, bytes and receives bytes, what the bytes mean is up to the user.

The code uses ```clojure.core.async``` heavily to transmit messages for read, write and exceptions.


Note: This library is still under construction, but you are welcom to look at the code and try it out.

Contact: feel free to contact me at <EMAIL>

## Usage

The binaries are published to https://clojars.org/clj-tcp

```[clj-tcp "0.2.15-SNAPSHOT"]```


```clojure


(use 'clj-tcp.echo-server :reload)
(def s (start-server 2324))
; this starts a test server, that reads echo and closes the channel

(use 'clj-tcp.client :reload)

(def c (client "localhost" 2324 {:reuse-client false}))
(read-print-in c)
(write! c (.getBytes "hi"))
;; read ...
;; any subsequent write! calls will find a closed channel, the connection will reconnect, and retry the send.

```

### Configuration

The following config options can be passed to the client



```clojure

(import 'io.netty.channel.ChannelOption)

(def c (client "localhost" 2324 {:handlers [default-encoder] ; ChannelHandlers that will be added to the Channel pipeline
                                  channel-options [[ChannelOption/TCP-NODELAY true]] ;io.netty.channel options a sequence of [option val] e.g. [[option val] ... ]
                                  retry-limit 5 ; on write error the client will retry the write this amount of times
                                  write-buff 100 ; writes are async, this is the buffer thats used for the clojure.async.channel
                                  read-buff  100 ; reads are written to the read channel, the buffer is specified here
				  error-buff 100 ; errors are sent to the error-ch, the buffer is specified here
                                  write-group (NioEventLoopGroup.) ;by default the same NioEventLoopGroup is used between connections
                                  read-group  (NioEventLoopGroup.) ;by default the same NioEventLoopGroup is used between connections, the same instance for the write-group and the read-group
        ))
```

## Contact

Email: <EMAIL>
Twitter: @gerrit_jvv

## License
<commit_msg>add rcvbuf example<commit_after># clj-tcp

A fast async tcp client library built on netty.

There are many good async http libraries out there, but no lowlevel tcp library that allows you to build your own protocols on top of it.
This library aims to provide this, you send, bytes and receives bytes, what the bytes mean is up to the user.

The code uses ```clojure.core.async``` heavily to transmit messages for read, write and exceptions.


Note: This library is still under construction, but you are welcom to look at the code and try it out.

Contact: feel free to contact me at <EMAIL>

## Usage

The binaries are published to https://clojars.org/clj-tcp

```[clj-tcp "0.2.15-SNAPSHOT"]```


```clojure


(use 'clj-tcp.echo-server :reload)
(def s (start-server 2324))
; this starts a test server, that reads echo and closes the channel

(use 'clj-tcp.client :reload)

(def c (client "localhost" 2324 {:reuse-client false}))
(read-print-in c)
(write! c (.getBytes "hi"))
;; read ...
;; any subsequent write! calls will find a closed channel, the connection will reconnect, and retry the send.

```

### Configuration

The following config options can be passed to the client



```clojure

(import 'io.netty.channel.ChannelOption)

(def c (client "localhost" 2324 {:handlers [default-encoder] ; ChannelHandlers that will be added to the Channel pipeline
                                  channel-options [[ChannelOption/TCP-NODELAY true][ChannelOption/SO_RCVBUF (int 5242880)]] ;io.netty.channel options a sequence of [option val] e.g. [[option val] ... ]
                                  retry-limit 5 ; on write error the client will retry the write this amount of times
                                  write-buff 100 ; writes are async, this is the buffer thats used for the clojure.async.channel
                                  read-buff  100 ; reads are written to the read channel, the buffer is specified here
				  error-buff 100 ; errors are sent to the error-ch, the buffer is specified here
                                  write-group (NioEventLoopGroup.) ;by default the same NioEventLoopGroup is used between connections
                                  read-group  (NioEventLoopGroup.) ;by default the same NioEventLoopGroup is used between connections, the same instance for the write-group and the read-group
        ))
```

## Contact

Email: <EMAIL>
Twitter: @gerrit_jvv

## License

{'fraction_non_alphanumeric': 0.08176495190296947, 'fraction_numerical': 0.0123379339188624, 'mean_word_length': 2.8386837881219904, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1101961', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1275, 'n_words': 600}