Current version: 0.17.x
»GeeXLab homepage

Current version: 1.19.1
»FurMark homepage
»FurMark 1.9.x Submissions

GPU Caps Viewer
Current version:
»GPU Caps Viewer homepage
»GPU DB Submissions

GPU Shark
Current version:
»GPU Shark homepage

»JeGX's HackLab

Geeks3D's Articles
»GPU Memory Speed Demystified

»Multi-Threading Programming Resources

»GeForce and Radeon OpenCL Overview

»How to Get your Multi-core CPU Busy at 100%

»How To Make a VGA Dummy Plug

»Night Vision Post Processing Filter

PhysX FluidMark
Current version: 1.5.2
»FluidMark homepage
»FluidMark 1.4.x Submissions

Current version: 0.3.0
»TessMark homepage

Current version: 0.3.0
»ShaderToyMark homepage
»ShaderToyMark Scores

Current Version: 1.23.0
»Libraries and Plugins
»Online Help - Reference Guide
»Codes Samples

3D Graphics Search Engine:

The Geeks Of 3D

The LUA SocketLib and the Coroutines

By Jerome Guinot aka 'JeGX' - jegx_AT_ozone3d(dot)net

Initial draft: May 2, 2006

[ Index ]

Introduction | Page 2 | Page 3 | Page 4 | Page 5

»Next Page

3 - Setting up a TCP/IP server

The usual procedure to create a TCP server can directly be applied with the SocketLib functions. This schema is the following one:

  • 1 - create a server half-socket
  • 2 - attach the half-socket to a port
  • 3 - listen on this port

The SocketLib being a part of Hyperion, it can be used like any other standard library provided with LUA (io, math, string, os, etc.) simply by calling its name with the socket.tcp() extension for example. The following code shows how to create the TCP server.

function createTCPServer( host, port, backlog )
	local tcp_server, err = socket.tcp();
	if tcp_server==nil then 
		return nil, err; 

	tcp_server:setoption("reuseaddr", true);
	local res, err = tcp_server:bind(host, port);
	if res==nil then
		return nil, err;

	res, err = tcp_server:listen(backlog);
	if res==nil then 
		return nil, err;

	return tcp_server;

socket.tcp() allows to create a TCP server object. It is then possible to access the server functions by separating the server name and the function name by 2 points: tcp_server:setoption(). A detailed explanation on functions and objects provided with the SocketLib is available in the project at the end of this page.

All the functions used after the creation of the server object are really well known for this kind of job: setoption(), bind() and listen().

Most of the SocketLib functions return one parameter if successful and two parameters if not. If a failure occurs, the first returned value is nil and the second value is the error message.

The createTCPServer() function must be called once during ths initialization of the host program. This is done in Hyperion just by inserting both the code and the call to that function in an initialization LUA script (run_mode="INIT").

Last thing: pay attention to the host parameter in createTCPServer() function. If you set it with "localhost", the TCP server will accept only localhost incoming connections (i.e the client is localized on the same computer than the server). So if you wish to be able to connect to your server from a client placed physically in another computer, you have to set host as follow: host = "*";. It's a little trick but believe me, you may waste much time if you don't know it!

Creating a TCP server is the easiest part. Let us tackle the hardcore one: the acceptation and the management of the in going connections.

[ Index ]

Introduction | Page 2 | Page 3 | Page 4 | Page 5

»Next Page

GeeXLab demos

GLSL - Mesh exploder

PhysX 3 cloth demo

Normal visualizer with GS

Compute Shaders test on Radeon

Raymarching in GLSL

Geeks3D latest news

Geeks3D forum news

»Texture DataPack #1
»Asus Silent Knight CPU Cooler
Page generated in 0.0067880153656006 seconds.