Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
975905de
Commit
975905de
authored
9 years ago
by
ocelot-inc
Browse files
Options
Downloads
Patches
Plain Diff
socket.rst another example
parent
ad7dc7dc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/sphinx/reference/socket.rst
+53
-1
53 additions, 1 deletion
doc/sphinx/reference/socket.rst
with
53 additions
and
1 deletion
doc/sphinx/reference/socket.rst
+
53
−
1
View file @
975905de
...
...
@@ -395,7 +395,7 @@ the function invocations will look like ``sock:function_name(...)``.
.. method:: name()
The ``
The
sock:name()`` function is used to get information about the
The ``sock:name()`` function is used to get information about the
near side of the connection. If a socket was bound to ``xyz.com:45``,
then ``sock:name`` will return information about ``[host:xyz.com, port:45]``.
The equivalent POSIX function is ``getsockname()``.
...
...
@@ -504,6 +504,58 @@ computer to communicate with itself, but shows that the system works.
- true
...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use tcp_server to accept file contents sent with socat
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is an example of the tcp_server function, reading
strings from the client and printing them. On the client
side, the Linux socat utility will be used to ship a
whole file for the tcp_server function to read.
Start two shells. The first shell will be the server.
The second shell will be the client.
On the first shell, start Tarantool and say:
.. code-block:: lua
box.cfg{}
socket = require('socket')
console = require('console'); console.delimiter('!')
socket.tcp_server('0.0.0.0',
3302,
function(s)
while true do
request = s:read("\n");
if request == "" then break end
if request == nil then break end
print(request)
end
end)
console.delimiter('')!
The above code means: use tcp_server() to wait for a
connection from any host on port 3302. When it happens,
enter a loop that reads on the socket and prints what it
reads. The "delimiter" for the read function is "\\n" so
each read() will read a string as far as the next line feed,
including the line feed.
On the second shell, create a file that contains a few
lines. The contents don't matter. Suppose the first line
contains A, the second line contains B, the third line
contains C. Call this file "tmp.txt".
On the second shell, use the socat utility to ship the
tmp.txt file to the server's host and port:
.. code-block:: lua
socat TCP:localhost:3302 ./tmp.txt
Now watch what happens on the first shell.
The strings "A", "B", "C" are printed.
.. _luasocket: https://github.com/diegonehab/luasocket
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment