This repository has been archived by the owner on Jan 3, 2018. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
couv/examples/tcp-echo-client.lua
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
31 lines (23 sloc)
682 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local uv = require 'couv' | |
| local TEST_PORT = 9123 | |
| coroutine.wrap(function() | |
| local handle = uv.Tcp.new() | |
| handle:connect(uv.SockAddrV4.new('127.0.0.1', TEST_PORT)) | |
| handle:startRead() | |
| handle:write({"PING"}) | |
| print('tcp_client send message {"PING"}') | |
| local nread, buf = handle:read() | |
| if nread and nread > 0 then | |
| print("tcp_client read msg=", buf:toString(1, nread)) | |
| end | |
| handle:write({"hello, ", "tcp"}) | |
| print('tcp_client send message {"hello, ", "tcp"}') | |
| nread, buf = handle:read() | |
| if nread and nread > 0 then | |
| print("tcp_client read msg=", buf:toString(1, nread)) | |
| end | |
| handle:write({"QUIT"}) | |
| handle:stopRead() | |
| handle:close() | |
| end)() | |
| uv.run() |