GeeXLab
Current version: 0.45.1
>GeeXLab homepage

FurMark
Current version: 1.30.0
>FurMark homepage

GPU Caps Viewer
Current version: 1.55.0.0
>GPU Caps Viewer homepage

GPU Shark
Current version: 0.26.0.0
>GPU Shark homepage


Blogs
>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.4
>FluidMark homepage

TessMark
Current version: 0.3.0
>TessMark homepage

ShaderToyMark
Current version: 0.3.0
>ShaderToyMark homepage
>ShaderToyMark Scores

Demoniak3D
Current Version: 1.23.0
>Demoniak3D
>Download
>Libraries and Plugins
>Demos
>Online Help - Reference Guide
>Codes Samples
 
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; 
	end

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

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

	return tcp_server;
end

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



Misc
>Texture DataPack #1
>Asus Silent Knight CPU Cooler
Page generated in 0.0022151470184326 seconds.