Important alert: (current site time 7/16/2013 3:57:26 AM EDT)
 

winzip icon

Web Server example Code version .3a FIXED (2nd)

Email
Submitted on: 12/19/1999
By: Pat 
Level: Intermediate
User Rating: By 4 Users
Compatibility: VB 5.0, VB 6.0
Views: 20879
 
     This is an example project on how to create a web server. I looked on this site and haven't seen any, so i decided to make one. I commented everythign as much as i could. Let me know what you think about it :) This code has been updated. I removed the pause of .4 seconds and moved the code to sckWS_SendComplete. I want to thank Ron for letting me know that it would slow it down. :) Please post any suggestions/improvments or just your thoughts on it. :) 'v .2a fixed: some loading problems 'v .3a fixed: fixed the $ip linking problem, everything works now. :) ' also fixed: i made the project compatible with vb5 by removing the replace ' function. ' Creating a link to another page ' To link to another page, link to 'http://$ip/page_name.html' 'The webserver will replace $ip with your ip. The webserver also 'supports files in other directories in the html dir. You could link 'to test.html in the directory 'links' by linking to: ' http://$ip/links/test.html ' ' PLEASE REPORT ANY BUGS! ' pat - nymainst@nais.com Please visit my webpage @ http://momar.net/pat :)
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

12/19/1999 9:17:17 PMLimbokid

Absolutely incredible! Nice code, simple interface and - what a nice feature - IT WORKS!

Keep up the awesome work :)
(If this comment was disrespectful, please report it.)

 
12/19/1999 9:21:38 PMPat

Why thank you :) I hope you understood it. At a point when i get a chance, i'll probably code some other things i haven't seen on here with winsock :)

Please rate my work if you like it, it makes me feel *special*, lol :)
(If this comment was disrespectful, please report it.)

 
12/19/1999 10:49:33 PMOmar

Please Keep It Up!!!
(If this comment was disrespectful, please report it.)

 
12/19/1999 10:55:41 PMRon

Great Code Dude..
Keep It UP.
(If this comment was disrespectful, please report it.)

 
12/20/1999 12:44:11 AMRon Serber

Good work,

Why are you using the timeout 0.4
Is there a more elegant way to do this?
(If this comment was disrespectful, please report it.)

 
12/20/1999 12:48:19 AMPat

You have to pause after sending the data, then close the connection. i've found that .4 seconds works best :) yes, there is a more elegant way to do this though. You'd need to code something into the sckWS_TransferFinished sub. :) i was thinking about doing it.
(If this comment was disrespectful, please report it.)

 
12/20/1999 5:14:19 AMAmritanshu

Great Code man....

(If this comment was disrespectful, please report it.)

 
12/20/1999 9:43:14 AMEnCrY

"clap" , "clap" , "clap", "cLAP"
(If this comment was disrespectful, please report it.)

 
12/20/1999 1:48:34 PMAhmad Hosseini

I get run time erro 10048.
Address in use.
What does it mean. How can I resolve it.
Thanks
(If this comment was disrespectful, please report it.)

 
12/20/1999 3:24:21 PMBrandon

Pat I dont know if you will read this first before you check your email but if you do then check your email right now for my question please
(If this comment was disrespectful, please report it.)

 
12/20/1999 3:52:30 PMPat O'Laughlin

Very nice example.
(If this comment was disrespectful, please report it.)

 
12/20/1999 7:40:20 PMJason

This code doesnt work in VB 5.0 Because VB 5 does allow the Replace command.
Also VB 5 needs the "Retained" key removed...
(If this comment was disrespectful, please report it.)

 
12/20/1999 7:55:10 PMSlyOne

Hey Ahmad Hosseini the solosion(Don't know how to spell) to the error 10048 is reinstall the adapter that the app is running off that has TCP/IP.
(If this comment was disrespectful, please report it.)

 
12/20/1999 8:24:58 PMMillenium Software

Excellent code! This is the first web server I've seen in VB that works so well.
(If this comment was disrespectful, please report it.)

 
12/20/1999 11:27:07 PMjared

well done pat. i used some of your ideas and the basic layout of your form to create a server more adapted to my needs. i added command line switches for easy startup/minimization upon loading... as well as a tray icon and animated tray minimization.

screenshot - http://24.48.73.8/
(If this comment was disrespectful, please report it.)

 
12/20/1999 11:33:45 PMOmar

Thanks for that bug fix Pat
(If this comment was disrespectful, please report it.)

 
12/21/1999 3:56:54 PMNo0ne

Nice! And well put together.
(If this comment was disrespectful, please report it.)

 
12/22/1999 1:41:41 PMTj

Really cool,really cool!!!
The best code I have seen here...
Keep on the great work...
(If this comment was disrespectful, please report it.)

 
12/23/1999 6:53:28 PMRob

When there are pictures on the pages, they do not load. Does that require extra coding?
(If this comment was disrespectful, please report it.)

 
12/30/1999 8:30:39 AManders

Rob is right, the pictures dos'nt load, please fix it. Thanks.
(If this comment was disrespectful, please report it.)

 
1/4/2000 1:46:21 PMJMDickson

Every get loads a new winsock, even when the others are not in use. This eats about 4k per get that is never released.

To use images replace text_read with:

Public Function text_read(filename)

Dim intFileNum As Integer
Dim strFile As String
Dim lngLength As Integer

On Error Resume Next
intFileNum = FreeFile
strFile = ""
If FileExists(filename) Then
If Len(filename) Then
Open filename For Binary As #intFileNum ' Open file.
strFile = Space(FileLen(filename))
Get #1, , strFile
Close #intFileNum
End If
End If
text_read = strFile
End Function
(If this comment was disrespectful, please report it.)

 
1/5/2000 6:01:37 AMplotoder

any idea on how to run cgi scripts with this one
(If this comment was disrespectful, please report it.)

 
1/7/2000 5:19:06 PMjoox

if you want a webserver which support images. download this one: webserver
(If this comment was disrespectful, please report it.)

 
1/10/2000 2:02:19 AMMitch

Great Code but could have some better error handling. Also going to http:///../ will freeze the server. Anyway to fix this? And also, is there any way to list the files, as in FTP? Thanks :) [webmaster@mitch.zzn.com]
(If this comment was disrespectful, please report it.)

 
1/17/2000 4:55:56 AMNeil Ramsbottom

I have just started my own webserver project and this answers quite a few of my question. Lemme know if you need a VB5 coder.
(If this comment was disrespectful, please report it.)

 
1/17/2000 2:10:05 PMSB

Hey, good Idea Wizdum.. you wanna see his mad skillz at work? Goto www.theblackhand.net and download this work of art
(If this comment was disrespectful, please report it.)

 
1/18/2000 12:56:03 PMAlex

I've a question, when I typ http://(My I.P.)/Index.html the server says that someone is connected but in internet explorer ther is no page vissible. The server and the html files are in the same directory, does anyone know what I'm doing wrong?
(If this comment was disrespectful, please report it.)

 
1/18/2000 2:41:21 PMBrian

Is this for VB 6 only, I have VB 5.0 and can not open the project. I recive a "Retained" invalid key error?

Help Please!
(If this comment was disrespectful, please report it.)

 
1/18/2000 2:55:38 PMBrian

I think I know what the problem is know... the reference lines in the project file are pointing to files in the ..\..\..\WINDOWS\SYSTEM directory which of course will cause the errors I am getting becuase I use NT and there for do not have a windows directory per-say... I changed that, and it seems to function ;)
(If this comment was disrespectful, please report it.)

 
1/23/2000 11:44:42 AMJack Edin

Great work! Thank you.
I needed a working example of a Winsock Listener to modify into something completely different than a webserver...
Luckily for me I built on THIS fine piece of work! Couldn't have done it without ya, buddy... Thankx again!!
(If this comment was disrespectful, please report it.)

 
1/24/2000 10:16:12 AMMe

Hey Brian, If you got a "retained" key when opening in VB5, try this:
1) Open up notepad
2) Open up the .vbp of this code
3) Delete the line near the bottom that says "retained=..."
4) Save it and open the project in VB and your fixed up.
(If this comment was disrespectful, please report it.)

 
1/28/2000 7:19:45 AMjosh

great example code, just one question though, your example always lists my ip as: http://4.0.0.3, for some reason, it will work fine if I go to my actual ip addy but links won't work because it thinks my ip is the one above is this because I am on a proxy server? and is there anyway to fix it?
(If this comment was disrespectful, please report it.)

 
1/29/2000 1:27:12 AMJim

I love your code but is there any way to make it more stable? It is so easy to lockup the program. All you need to do is type something wierd into the browser and the web server program freezes. i.e. type http://127.0.0.1//
or
http://127.0.0.1/..

Would you need to filter out every possible bad command or is it possible to just check if it is valid?
(If this comment was disrespectful, please report it.)

 
2/8/2000 7:21:43 AMFred

Just one thing, the way you said to change the 404 error so that it loads a html 404 error page for me does not work, it just makes a page with the directory of the html page is there a way to fix this? does this happen for anyone else or just me?
(If this comment was disrespectful, please report it.)

 
2/8/2000 10:34:33 PMsub

Fred you need to change part of the sckWS_ConnectionRequest sub as well, the part I am reffering to should look like this:

requestedPage$ = html_404$
htmldata$ = text_read(htmlPageDir & "\" & "404.html") 'This reads the file and stores it's contents in htmldata$
htmldata$ = ReplaceStr(htmldata$, "$ip", sckWS(0).LocalIP) 'Oops, i didn't use the replace function right. Now it's fixed at replaces $ip with your IP.
sckWS(ttlConnections).SendData htmldata$ & vbCrLf

instead of this(this is off the top of my head so may be wrong):

requestedPage$ = "/a"
sckWS(ttlConnections).SendData html_404$
(If this comment was disrespectful, please report it.)

 
5/18/2000 12:40:37 PMap

man.. this is great...what else can i say
(If this comment was disrespectful, please report it.)

 
9/8/2003 8:26:33 AMykristiawan

Very good one, 5 globes from me. Are you planning to enhance your program to handle HTTP POST?
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.