Warning: Undefined array key "HTTP_ACCEPT_LANGUAGE" in /home/clients/50536745d503cc9bd290722a231d5f8f/web/includes/o3_common.php on line 79

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home/clients/50536745d503cc9bd290722a231d5f8f/web/includes/o3_common.php on line 79
oZone3D.Net Tutorials - The LUA Socket Lib and Coroutines - Setting up a simple TCP server




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



5 - La démo

First, a little screenshot:



The demo that comes with this tutorial allows to drive the rotation of a torus by changing the 3 Euler's angles: pitch, yaw and roll. The interesting thing is that the Euler's angles modification is done by a remote all-purposes TCP client:



The TCP client's functioning is hyper-simple: just enter the server name (characters string representing the hostname or IP address - ex: 127.0.01 or HyperionServer), the server's port and the message to be sent. The TCP client adds automatically a '\n' at the end of the message in order to respect the server protocol. Then, [Send Message] allows to send the message to the server. The checkbox allows to wait for a server reply. The demo's TCP server returns to the client the HYP_OK string if the client has sent a valid command or HYP_UNKNOWN_COMMAND in case of invalid command.

Load the DEMO_LUA_TCP_Server_Coroutine.xml file in Hyperion and start the TCP client. Then send, from the client, the following command:

pitch +100.0

The torus angular speed is now equal to 100.0 degrees / second. The general format of the command is:

pitch +/-[value] +/-yaw [value] +/-roll [value]

The following commands are all valid:

pitch +100.0 roll -20.0
yaw -50.0

This little demo allows us to use a very handy function of the LUA string lib: string.gmatch(). This function allows to analyze the client message and look up the Euler's angles (in 3 global variables):

function extractEulerAngles( command )
  local ok = 0;
  for angle_name, angle_value in string.gmatch(command, "(%a+) (%p%d+%p%d+)") do
      if angle_name=="pitch" then
        g_pitch_step = tonumber(angle_value);
        ok = 1;

      elseif angle_name=="yaw" then
        g_yaw_step = tonumber(angle_value);
        ok = 1;

      elseif angle_name=="roll" then
        g_roll_step = tonumber(angle_value);
        ok = 1;

      end
    end

  return(ok);
end

Each call to string.gmatch() analyzes the command string pattern by pattern. In our case, the pattern is (%a+) (%p%d+%p%d+).

The pattern (%a+) allows to extract the angle's name (pitch, yaw or roll) and stores this name in the angle_name variable. The pattern (%p%d+%p%d+) allows to extract the angle's value in order to store it in angle_value.

For example, the pitch +100.0 roll -20.0 yaw +10.0 command contains 3 patterns and pitch +100.0 contains only one.

I don't get deeper into the detail, please see the LUA 5.1 reference guide available at www.lua.org for more information about patterns.



6 - Further reading


7 - Downloads


Demoniak3D project
Last update: May 5, 2006

*** These source codes require Demoniak3D to run properly.
Demoniak3D is available here: [:: Demoniak3D Demo-System ::].



All purposes Win32 TCP Client
Mise à jour: May 5, 2006


LUA SocketLib Official Doc




[ Index ]

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





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.0032360553741455 seconds.