Ecere SDK/eC Forums • View topic - Sample httpserver from gui app to non-gui app




Ecere SDK/eC Forums

Ecere Developers Community

Sample httpserver from gui app to non-gui app

General help with the eC language.

Sample httpserver from gui app to non-gui app

Postby sjps » Thu Mar 02, 2017 5:16 am

Hi All,

I am trying to make the httpserver sample into a non-gui app.

What else is needed, please ?

class HTTPApplication : Application
{
bool Init()
{
httpServer.Start();
return true;
}

bool Cycle(bool idle)
{
bool result = true;
HTTPClient client, next;
for(client = (HTTPClient)httpServer.firstClient; client; client = next)
{
next = (HTTPClient)client.next;
if(client.f)
{
#define PACKETSIZE 65536

static byte buffer[PACKETSIZE];
int read = client.f.Read(buffer, 1, PACKETSIZE);

if(read)
client.Send(buffer, read);
if(client.f.Eof())
{
delete client.f;
if(client.close)
client.Disconnect(0);
}

result = true;
}
}
return result;
}
}

HTTPServer httpServer { port = 8080 };

//Window serverWindow { size = Size { 320, 200 }, text = "ECERE HTTP Server", hasMinimize = true, hasClose = true };
sjps
 
Posts: 10
Joined: Sun Feb 26, 2017 10:22 am

Re: Sample httpserver from gui app to non-gui app

Postby sjps » Thu Mar 02, 2017 5:23 am

It had no main, so I will post it here in case someone else has the same problem.

class HTTPApplication : Application
{
bool Init()
{
httpServer.Start();
return true;
}

bool Cycle(bool idle)
{
bool result = true;
HTTPClient client, next;
for(client = (HTTPClient)httpServer.firstClient; client; client = next)
{
next = (HTTPClient)client.next;
if(client.f)
{
#define PACKETSIZE 65536

static byte buffer[PACKETSIZE];
int read = client.f.Read(buffer, 1, PACKETSIZE);

if(read)
client.Send(buffer, read);
if(client.f.Eof())
{
delete client.f;
if(client.close)
client.Disconnect(0);
}

result = true;
}
}
return result;
}
void Main ()
{
getchar();
}

}

HTTPServer httpServer { port = 8080 };

//Window serverWindow { size = Size { 320, 200 }, text = "ECERE HTTP Server", hasMinimize = true, hasClose = true };
sjps
 
Posts: 10
Joined: Sun Feb 26, 2017 10:22 am

Re: Sample httpserver from gui app to non-gui app

Postby sjps » Thu Mar 02, 2017 5:36 am

My next question is that if I link against ecere, the app works, but pulls in all the X libraries, but should not be needed now:

ldd obj/release.linux/httpServer
/lib/ld-musl-i386.so.1 (0x50fd8000)
libecere.so.0 => /usr/lib/libecere.so.0 (0x50d15000)
libc.musl-x86.so.1 => /lib/ld-musl-i386.so.1 (0x50fd8000)
libjpeg.so.8 => /usr/lib/libjpeg.so.8 (0x50cae000)
libpng16.so.16 => /usr/lib/libpng16.so.16 (0x50c7a000)
libz.so.1 => /lib/libz.so.1 (0x50c62000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x50bb7000)
libncursesw.so.6 => /usr/lib/libncursesw.so.6 (0x50b63000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x50b22000)
libgif.so.7 => /usr/lib/libgif.so.7 (0x50b18000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x509e6000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x509d3000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x509c8000)
libGL.so.1 => /usr/lib/libGL.so.1 (0x50936000)
libbz2.so.1 => /usr/lib/libbz2.so.1 (0x50929000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0x50909000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x508df000)
libxcb-dri3.so.0 => /usr/lib/libxcb-dri3.so.0 (0x508db000)
libxcb-present.so.0 => /usr/lib/libxcb-present.so.0 (0x508d7000)
libxcb-sync.so.1 => /usr/lib/libxcb-sync.so.1 (0x508cf000)
libxshmfence.so.1 => /usr/lib/libxshmfence.so.1 (0x508cb000)
libglapi.so.0 => /usr/lib/libglapi.so.0 (0x5087e000)
libXdamage.so.1 => /usr/lib/libXdamage.so.1 (0x5087a000)
libXfixes.so.3 => /usr/lib/libXfixes.so.3 (0x50873000)
libX11-xcb.so.1 => /usr/lib/libX11-xcb.so.1 (0x50870000)
libxcb-glx.so.0 => /usr/lib/libxcb-glx.so.0 (0x50854000)
libxcb-dri2.so.0 => /usr/lib/libxcb-dri2.so.0 (0x5084e000)
libXxf86vm.so.1 => /usr/lib/libXxf86vm.so.1 (0x50847000)
libdrm.so.2 => /usr/lib/libdrm.so.2 (0x50836000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x50832000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x5082b000)

If I link against ecereCOM it is much more in line with what I want:
ldd obj/release.linux/httpServer
/lib/ld-musl-i386.so.1 (0x507bc000)
libecereCOM.so.0 => /usr/lib/libecereCOM.so.0 (0x50759000)
libc.musl-x86.so.1 => /lib/ld-musl-i386.so.1 (0x507bc000)

But it segfaults when I try to run it.
What is the proper way to make a non-gui app that uses the network capabilities of ecere ?
sjps
 
Posts: 10
Joined: Sun Feb 26, 2017 10:22 am

Re: Sample httpserver from gui app to non-gui app

Postby sjps » Thu Mar 02, 2017 5:53 am

The approach of adding main above is wrong.

I am familiar with normal C and perl, so the OO style is not intuitive for me.
Sorry
sjps
 
Posts: 10
Joined: Sun Feb 26, 2017 10:22 am

Re: Sample httpserver from gui app to non-gui app

Postby jerome » Sat Mar 04, 2017 1:27 am

Hi Paul,

At this point in time, the networking functionality is only included within the libecere library, which also includes the GUI stuff and unfortunately has a dependency on the X libraries.

The libecereCOM only includes the very minimal stuff for the eC runtime.

As part of our 2017 roadmap, we have plans to address that and split libecere into multiple libraries with minimal dependencies.

In the meantime however there is no easy way to split the GUI from the networking. However, it should be easy enough to build a networking library without the X dependencies by only including the NCurses interface (ecere/src/gui/drivers/NCursesInterface.ec) and graphics driver (ecere/src/gfx/drivers/NCursesDisplayDriver.ec), and omitting the X11 ones (ecere/src/gui/drivers/XInterface.ec and ecere/src/gfx/drivers/XDisplayDriver.ec). It would require some .epj projects and/or Makefiles tweaks, and possibly some #ifdef's in the source code as well.

You should still inherit from 'GuiApplication' rather than 'Application' however, as the network processing loop is part of the GuiApplication class. We hope to fix that as well.

If you don't want to bring up even an NCurses terminal window to keep the app running, you can simply override GuiApplication::Main() and run a loop that will call the 'WaitNetworkEvent()' and 'ProcessNetworkEvents()' methods.

Sorry for the late reply, been especially busy this last week. Please let me know if you run into further issues or have any further questions.

Best regards,

-Jerome
jerome
Site Admin
 
Posts: 613
Joined: Sat Jan 16, 2010 11:16 pm

Re: Sample httpserver from gui app to non-gui app

Postby sjps » Mon Mar 06, 2017 9:48 am

Hi Jerome,

Thank you for taking the time to answer my questions.

I was wondering if it would work if I make static libraries of libecere and libecereCOM ?

Does it rely on those (or any other) being dynamic libraries ?

Regards
Paul
sjps
 
Posts: 10
Joined: Sun Feb 26, 2017 10:22 am

Re: Sample httpserver from gui app to non-gui app

Postby jerome » Mon Mar 06, 2017 9:57 am

Hi Paul,

The compiler needs a dynamic version of the library when compiling modules making use of them. However it is possible to link the final application with static versions of them. To build static versions of libecere, use either the the 'static' or the 'vanilla' configuration that you will find in ecere.epj (vanilla should already be pre-compiled/installed in the lib/ folder as libecereVanilla.a). Vanilla is kept smaller by excluding 3D graphics, a number of bitmap formats and display drivers. You can of course customize a configuration with exactly what you would like to include. Likewise, libecereCOM has a 'static' configuration.

To link your application statically, it will need to import the library as such:
import static "ecere"
Often we use a pre-processor definition to have the option to link statically or not:

import ECERE_STATIC "ecere"

Where ECERE_STATIC is either nothing or 'static'.

And then the static version of the library you wish to use must be specified in the Project Settings/Linker Options. Additinally, all libecere dependencies must be linked with directly in your application, and resources added to the 'libecere' library must then be included within your project's resources under an 'ecere' folder.

You can take a look at the eC/staticLink samples for reference:

https://github.com/ecere/ecere-sdk/tree ... staticLink

However it would seem this one is only configured to build with Windows and would need Linux library dependencies to be added in the Project Settings/Linker options under Static config/Linux platform.

Best regards,

-Jerome
jerome
Site Admin
 
Posts: 613
Joined: Sat Jan 16, 2010 11:16 pm

Re: Sample httpserver from gui app to non-gui app

Postby sjps » Mon Mar 06, 2017 3:38 pm

cool, thanks

Another thing is I remember vaguely reading about your own "JSON" implementation called ESON.

I am unable to find anything on the topic again. Maybe I am mistaken.

I would appreciate it if you can point me to some documentation/examples involving that (If it exists).


Regards
Paul
sjps
 
Posts: 10
Joined: Sun Feb 26, 2017 10:22 am

Re: Sample httpserver from gui app to non-gui app

Postby jerome » Mon Mar 06, 2017 6:24 pm

Hi Paul,

Yes it's called ECON: http://ec-lang.org/econ/

You can use WriteECONObject() to write out an object as ECON:
Code: Select all
public bool WriteECONObject(File f, Class objectType, void * object, int indent)


And ECONParser::GetObject() to retrieve an object from ECON:
Code: Select all
public JSONResult ECONParser::GetObject(Class objectType, void ** object)


Alternatively you can use WriteJSONObject() and JSONParser() to save to / retrieve from JSON. ECON aims to be a super set of JSON, but there are further restrictions on identifiers to be able to save as ECON (e.g. valid eC identifiers for 'keys').

There are no samples yet showing how to use it but you can find example of it in the Ecere IDE's source code.

Best regards,

-Jerome
jerome
Site Admin
 
Posts: 613
Joined: Sat Jan 16, 2010 11:16 pm


Return to eC Language

Who is online

Users browsing this forum: No registered users and 2 guests

cron