flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > TCP/IP Web Server

Author
Thread Post new topic Reply to topic
f14t



Joined: 27 Sep 2006
Posts: 36
f14t 27 Sep 2006, 12:10
Hi to all FASM users/lovers !

I have written a TCP/IP Web Server for Linux using ofcourse FASM.
The program uses Linux System Calls. And as it should be is really
tiny in size.

It can send html pages in response to requests.

I want to improve on it. Make it featureful and powerful.

Do anybody knows some ways for writing a good Server.
A person with experience in this area will be of great help.

Waiting for suggestions and help.

Thanks for paying attention.
Post 27 Sep 2006, 12:10
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista 27 Sep 2006, 12:59
hi f14t (cool nick). I think Dex4U did one not too long ago. I don't have time this moment to look for it. but you can search for Dex4U posts and find it here on the board.

cheers!
Post 27 Sep 2006, 12:59
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Sep 2006, 13:19
wouldn't you post your sources?
Post 27 Sep 2006, 13:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
arafel



Joined: 29 Aug 2006
Posts: 131
Location: Jerusalem, Israel
arafel 27 Sep 2006, 13:34
f14t wrote:

I want to improve on it. Make it featureful and powerful.

Well, since web server's basic purpose is to handle and process numerous requests at the same time it would be wise to improve on the basic design first, so if you use simple threaded model it would wise switching to AIO.

As for other, less important, features: some kind of modular interface like Apache's one (so for example webserver could work with ssl, perl interpreter, etc. ) is a big plus.
Post 27 Sep 2006, 13:34
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 29 Sep 2006, 01:14
Yes HyperVista, is right i am making a web server for my OS Dex4u, fully tested and works fine, but need to add more drivers and function etc.
Taking abit of a break, working on porting Dex4u to ARM.
Info here: http://jas2o.forthworks.com/dexforum/index.php?topic=114.0
http://jas2o.forthworks.com/dexforum/index.php?topic=117.0
http://board.flatassembler.net/topic.php?t=5650
Post 29 Sep 2006, 01:14
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 29 Sep 2006, 06:43
f14t: look at /dev/epoll if you want to handle many clients.
Post 29 Sep 2006, 06:43
View user's profile Send private message Visit poster's website Reply with quote
f14t



Joined: 27 Sep 2006
Posts: 36
f14t 14 Oct 2006, 10:29
the guy who started it all

vid wrote:
wouldn't you post your sources?


no.
because i cant.
technically speaking, i browse the net in a cafe. and i write my programs
at home on my no-feature and frills intel PC.
apparentyl i don't have a cd-writer or a working floppy-drive to take my
code from home to cafe.

thanks every-body for replying.
sorry for the curious ones, i really am unable to share my code.

Sad [/b]
Post 14 Oct 2006, 10:29
View user's profile Send private message Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 19 Oct 2006, 15:14
Well, i've coded one of these as well. Very simple, but small, and fast.

Be warned though, its very nasty code (I dont comment, and ive probably left out some really obvious possible optimizations (if you can see any which would make a big difference, would love to hear about them)).

It uses linux syscalls and sends the files using the kernel call sendfile (187).

It's multithreaded, and very fast, (Its what i usually use to transfer large files over the LAN, or to temporarily host files for people to download). And since it doesnt use any external library, has a very small memory footprint.

Another warning: dont use it for real purposes Very Happy. Not for my sake, but the httpd is _very_ unsecure, for example, if you run it, then use a browser to go to http://127.0.0.1//etc/passwd ... well.. you can guess what happens Smile I do plan to fix this some time.. but got so much coursework to do for university, it's hard to find the time.

Use the code as you wish though, and oh, the string converting functions at the bottom of the code aren't mine, i saw them on this forum (sorry, cant remember who coded them), and they were a lot better than the ones i made.

And just before i give you the code, the usage for the httpd is either ./httpd, which runs the the server on port 80 using the current directory as the webroot, otherwise, ./httpd <portnumber> to run it on the port number you want (without the <>.. so: ./httpd 15023 for example).



Edit: The code's been updated, and moved to 3 posts down.


Last edited by gunblade on 05 Nov 2006, 03:56; edited 1 time in total
Post 19 Oct 2006, 15:14
View user's profile Send private message Reply with quote
f14t



Joined: 27 Sep 2006
Posts: 36
f14t 31 Oct 2006, 10:38
Thanks Gun Blade (Steel one or Iron one) !

I will try your code at home.

Smile
Post 31 Oct 2006, 10:38
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 31 Oct 2006, 10:47
gunblade: in fact, your code looks pretty straightforward and nice. it would be nice to add some comments and make example from it
Post 31 Oct 2006, 10:47
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 05 Nov 2006, 04:06
Wow, its quite scary how many bugs i found in this code, yet somehow it managed to balance the bugs into a working program.

Anyway, I've commented and fixed up the code. Now the automatic redirection to index.html if you try to open a directory in your browser works fine. More description is in the code.

This time round I'll upload the source as a file, seeing as it's now 517 lines long.

Any other flaws/ideas/comments you have on the code, I'd be happy to hear about. I learned quite a lot from going over this code again, and fixing all those errors. I also stayed awake until 4am without noticing. Laughing

If anyone feels like including this in any examples thread/package/page, or grabbing any of the code for their own things, feel free. It shows the basics of sockets, threads, and handling signals in linux.


Description: Linux multithreaded HTTPd
Download
Filename: httpd.asm
Filesize: 11.25 KB
Downloaded: 1198 Time(s)

Post 05 Nov 2006, 04:06
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 05 Nov 2006, 15:02
gunblade, why do you use sys_fork? There is no "CreateThread" syscall?

Maybe sys_clone can create a thread?(I'm not sure)

[edit] I found this http://www.die.net/doc/linux/man/man2/clone.2.html [/edit]
Post 05 Nov 2006, 15:02
View user's profile Send private message Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 05 Nov 2006, 15:55
I indeed could use sys_clone, but is there a specific reason I'd want to use it? As far as i can tell, the main difference between clone and fork is that clone makes a copy of the stack (and even the data?), which is unnecessary in my code.

(Unless you've spotted a mistake that I haven't picked up, in which case please do tell Smile)

Thanks,
gunblade
Post 05 Nov 2006, 15:55
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 05 Nov 2006, 16:17
fork create a completely new process which is a copy of its parent, but with clone (and the appropiate flags) creates a thread that shares the context with its parent so there is no memory copy. sys_clone is more similar to CreateThread of Windows (again, when you use the flags otherwise if you provide 0 its exactly the same that fork).

Here another link http://www.ibiblio.org/pub/Linux/docs/faqs/Threads-FAQ/html/
Post 05 Nov 2006, 16:17
View user's profile Send private message Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 05 Nov 2006, 16:45
Aah, whoops, must've gotten those mixed up.

Well ill look into it, see if it's any faster with the cloning rather than the forking, because I deffinetly don't need a full copy of all the data, only certain variables.

Thanks a lot Smile
Post 05 Nov 2006, 16:45
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 08 Nov 2006, 13:11
Is there a fork/clone/thread comparison? What do they actually mean and which is better in which case.
Post 08 Nov 2006, 13:11
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.