<commit_before>import msgpack_rpc
import msgpack
import asyncdispatch
import asyncnet
import os

when isMainModule:
  let
    addrUse = "127.0.0.1"
    portUse = Port(20001)
  let cl = commandLineParams()
  assert(len(cl) == 1)
  let t = cl[0] # server or client
  if t == "server":
    # Note:
    # We need unbuffered sockets for both client and server.
    # The reason is not found.
    let sock = newAsyncSocket(buffered=false)
    defer: sock.close()
    sock.bindAddr(address=addrUse, port=portUse)
    sock.listen()
    var server = mkServer(sock)
    server.addMethod("double", proc (args: openArray[Msg]): Msg =
      let a = unwrapInt(args[0])
      wrap(a * 2))
    asyncCheck server.run
    runForever()
  elif t == "client":
    let sock = newAsyncSocket(buffered=false)
    defer: sock.close()
    let client = mkClient(sock)
    waitFor sock.connect(address=addrUse, port=portUse)
    echo "call start"
    let fut1 = client.call(id=0, "double", @[PFixNum(100)])
    echo "call end"
    let ret1: Msg = waitFor(fut1)
    echo "ret: ", unwrapInt(ret1)
  else:
    assert(false)
<commit_msg>assert example<commit_after>import msgpack_rpc
import msgpack
import asyncdispatch
import asyncnet
import os

when isMainModule:
  let
    addrUse = "127.0.0.1"
    portUse = Port(20001)
  let cl = commandLineParams()
  assert(len(cl) == 1)
  let t = cl[0] # server or client
  if t == "server":
    # Note:
    # We need unbuffered sockets for both client and server.
    # The reason is not found.
    let sock = newAsyncSocket(buffered=false)
    defer: sock.close()
    sock.bindAddr(address=addrUse, port=portUse)
    sock.listen()
    var server = mkServer(sock)
    server.addMethod("double", proc (args: openArray[Msg]): Msg =
      let a = unwrapInt(args[0])
      wrap(a * 2))
    asyncCheck server.run
    runForever()
  elif t == "client":
    let sock = newAsyncSocket(buffered=false)
    defer: sock.close()
    let client = mkClient(sock)
    waitFor sock.connect(address=addrUse, port=portUse)
    echo "call start"
    let fut1 = client.call(id=0, "double", @[PFixNum(100)])
    echo "call end"
    let ret1: Msg = waitFor(fut1)
    assert(unwrapInt(ret1) == 200)
  else:
    assert(false)

{'fraction_non_alphanumeric': 0.12115732368896925, 'fraction_numerical': 0.022151898734177215, 'mean_word_length': 3.297087378640777, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1395416', 'n_tokens_mistral': 792, 'n_tokens_neox': 763, 'n_words': 208}