
The methodĬan be used immediately after creation to Sockets do not need to be connected before use. Networks are so good that, under normal circumstances, few errors Note that although no guarantees are made, these days Simplicity (no connection setup) and performance (no error checking or Only part of a datagram discards the rest, so that the following read Data transfers are atomic, one datagram at a time. Even when they do reach the other end, they are not guaranteed to beĮrror free. Other words, applications communicating through UDP send and receiveĭata as independent blocks, which are not guaranteed to reach the otherĮnd. UDP (User Datagram Protocol) is a non-reliable datagram protocol. if there was no error, send it back to the client

make sure we don't block waiting for this client's line Print("After connecting, you have 10s to enter a line to be echoed") Print("Please telnet to localhost on port ". find out which port the OS chose for us Local server = assert(socket.bind("*", 0)) create a TCP socket and bind it to the local host, at any port The program reads a line from the remote end and sends it back, closing Port (one that is chosen by the operating system) on the local host andĪwaits client connections on that port. The other methodsĪ simple echo server, using LuaSocket. Other methods available for server socket objects areĬlient sockets are used to exchange data between two applications over Once a connection is established, aĬlient socket object is returned representing this connection. On server sockets, applications can use the Which associates it with a remote address.

Master sockets are newly created TCP sockets returned by the functionĪfter it is associated with a local address by a call to theĬan be changed into a client socket with the method The library distinguishes three types of TCP sockets: master, Lines, arbitrary sized blocks or "read up to connection closed", all with Sockets in several different granularities: patterns are available for The library allows users to read data from the Reassembled transparently on the other end.
#MUDLET USE LUA SOCKET FREE#
Words, applications communicating through TCP can send and receive data asĪn error free stream of bytes. TCP (Transfer Control Protocol) is reliable stream protocol. Than it is in C, as the following sections will show. Together, these changes make network programming in LuaSocket much simpler Note that direct use of IP addressesįunctions from the DNS module are provided to convert between host names and IP addresses. Host name is given, the library queries the system's resolver and

Each LuaSocketĬall might perform several OS calls, so that the two timeout values areįinally, the host name resolution is transparent, meaning that mostįunctions and methods accept both IP addresses and host names. " block" timeout) or a combination of the two. The time LuaSocket can internally be blocked by any OS call (the The time it can be blocked by LuaSocket (the " total" timeout), on Method, an application can specify upper limits on Of the TCP domain will block the caller application until As in C, all I/O operations are blocking by default. Line by line, block by block, or until the connection is closed.Īll I/O reads are buffered and the performance differences betweenĭifferent receive patterns are negligible.Īnother advantage is the flexible timeout control One of the simplifications is the receive pattern capability.Īpplications can read data from stream domains (such as TCP) To achieve these goals, the LuaSocket API keeps the function names and semantics the C API whenever possible, but their usage in Lua has been greatly simplified. Second, the simplicity and the feel of the Lua language should be First, usersĮxperienced with the C API to sockets should feel comfortable using LuaSocket.

Interface to I/O across different domains and operating systems. Currently, support is provided for TCPĪnd UDP, but nothing prevents other developers from implementing SSL, Localĭomain, Pipes, File Descriptors etc. This introduction is about the CĬommunication in LuaSocket is performed via I/O objects. The SMTP (sending e-mails), HTTP (WWW access) and FTP (uploading andĭownloading files) protocols and other functionality commonly needed byĪpplications that deal with the Internet. That is composed by two parts: a C core that provides support for the TCPĪnd UDP transport layers, and a set of Lua modules that add support for
