# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  VB - A simple HTTP Web Server

## CVMichael

Commented, with very clear code.

A simple web-server project made for those who want learn about winsock, and how a web-server works...

*[Edit]*, By the way...
There is a newer version of this server here: VB - A simple HTTP Web Server (2)

----------


## janis

I just take a look your webserver, and I have one question: how to use that web server?

regards

----------


## CVMichael

Change the PathShared constant to the directory you want to share, then change the LocalPort for the winsock control to the port you want the web-server to listen on

The path that you are sharing, should have some html files.

If for example you have an html file named Index.html, then in your browser just type "http://localhost/Index.html", and then you'll see that file in the browser...

I did not make it list files in the directory, so you need to know the file names in that directory when you want to download a file from the web-server...

----------


## janis

Still I don't get it? Maybe more details?

regards

----------


## CVMichael

I've already explained it the best I could, if someone else knows how to explain it better, please do...

----------


## Edneeis

Open the code and in the General Declaration section change the Private Const PathShared As String to whatever folder you want to put your html files in.  Then in the Form_Load event change the Sck(0).LocalPort = line to: Sck(0).LocalPort = 80.  Next open a browser and type: http:\\localhost\ and a file name that you put in the folder (i.e index.htm).

----------


## blaff

Pretty cool!

(Although I can't really use it in my projects at the moment)

----------


## Fox

Note: The default port is 8080 so if you just changed the PathShared you should connect to http://YOUR_IP:8080/

Also I've seen there's no default file, you should probably correct this by hand. I inserted a line to make it working in most cases:


VB Code:
If RequestedFile = "/" Then: RequestedFile = "/index.html"

It's a pretty nice server but before using it in your projects you should spend some time with implementing stats and security functions. For example you should prevent the server from overwhelming / DoS attacks and such.

Anyways, good work!

----------


## CVMichael

*Fox*, There is ALWAYS something to add to a web-server, and trust me I know how to make one, if you look at my web-page you'll see I have a complete web-server *[Edit]*Website not in use anymore*[/Edit]* (click on "My Programs" a ~6700 line web-server)

The purpose for this one is to make the beginners understand how to even start to make one, that's why I've made it in as few lines as possible so a beginner will not get confused.

And about the stats and security... unless you implement a log for the server, I don't see how it would serve for anything... if there are requests for the cmd.exe (or something like that) it will just send a 404 error, and if the file IS there (in the share) then it will send the actual file instead of executing it... so why worry ?

----------


## hoanghiep

I want to find a FTP virtual  sever 
that I can upload or download file with FTP service

exam:
host: ftp.localhost
user: myname
pass: mypass

Please help me
Thanks

----------


## CVMichael

I don't know how to make an FTP server, I tried a long time ago, and I gave up, never tried since then... I did not need to... but if you just want to upload files onto a server, you can do it with an http server too... and obviously you can download with it also... The server I posted does not work if you try to upload, you will have to make some modifications to make it work for upload.

And *hoanghiep*, you are not supposed to ASK questions here, you do that in any other forum but this one... in this forum you only post code, and when you DO ask a question it should be about that particular code that was posted when starting the thread... in this case about the http server I posted...

I think your question is more suited in the General VB Questions Forum

----------


## francisd

Check out ActiveXperts Webserver at http://www.activexperts.com

----------


## CVMichael

> _Originally posted by francisd_ 
> *Check out ActiveXperts Webserver at http://www.activexperts.com*


So... why did you post that link in this thread ? Do they give the source code ?? Or are you just helping to promote their product ?

----------


## XcutiveD

*edited*

XcutiveD - grow up.

 - CB

----------


## mebhas

hey at least be thankful for the guy for showing us the code. if you really want to get good with programming then you should be able to analyzee and be able to figure out what the syntax or the procedure is supposed to do. i am downloading the piece and will try to analyse the code and understand it before asking any questions.

----------


## cokes

how come i cannot view images with this server?

----------


## cokes

dude, the starter of this subject "CVMicheal" or w/e, well your server doesnt display images and i dont know how to get it to work, and i dont like dreamvb's because i cannot get it in the systray for ****

----------


## penagate

Did you even read the thread? It's a simple example of how a web server works.

If you want to ask questions, post in the right forum. Codebank is not for questions.

Also, please be respectful when addressing other members. The least you can do is spell Michael's username right.

----------


## cokes

Sorry!!!!

----------


## CVMichael

Ah, I hate when people post to my old threads, because for some reason when they updated the vbforums, they did not mark old threads as subscribed... and I did not know that someone posted in the thread until now because I wanted to see what's new in the CodeBank... and I see my thread on top.

Anyways...

*dreamvb*, Why didn't you make your own thread ?

*cokes*, it should work with images, what kind of images are they, are they jpeg ?
Let me test and make sure...

By the way, I have another server (a newer version in the CodeBank)
Here: VB - A simple HTTP Web Server (2)

----------


## CVMichael

I tested it, and it works.... it shows the picture...

I made a simple test.html file:


```
<html>
<body>
<img src=test_picture.jpg></img>
</body>
</html>
```

I put the test_picture.jpg in the same directory as the html file
Changed the PathShared variable to where I put the html file and the jpg file, and then opened the web-page in the browser: http://localhost:8080/test.html
And it worked, it showed the picture just fine....

----------


## dreamvb

O I thought the project may have been of ome use to other people in the thread, saves them seraching around plus I thought it may have been some use to your self, But I was wrong. Anyway I now removed the thread and upload in my own sometime.

anyway Hope I never upset anyone.

----------


## alexvb74

Would any one know how to make it work with .asp files?

----------


## Daddyo

Very nice example, thanks!!

----------


## xlumination

wow, this is quite good, i had a look though it and it seems really nice!

Thanks alot, 

~xlumination

----------


## CVMichael

Thank you  :wave: 

It's really gratifying when I get replies like yours.

PS. Take a look at the new web server also (with minor changes to show directory structure). The link to it is in the first post.

----------


## xlumination

> Thank you 
> 
> It's really gratifying when I get replies like yours.
> 
> PS. Take a look at the new web server also (with minor changes to show directory structure). The link to it is in the first post.



No Problem Mate. 

I like the new one also! 

the directory structure is very good.


Keep it up!  :Thumb:

----------


## Joke Sparrow

hi i know this is old thread but i have a question about the path of the server.

Private Const PathShared As String = "C:\"

what if i want to change it to temp folder?
 i tried 
Private Const PathShared As String = Environ("tmp") & "\server" but it gives me an error..

help please?

----------


## mebhas

> hi i know this is old thread but i have a question about the path of the server.
> 
> Private Const PathShared As String = "C:\"
> 
> what if i want to change it to temp folder?
>  i tried 
> Private Const PathShared As String = Environ("tmp") & "\server" but it gives me an error..
> 
> help please?


a constant cannot be a calculated value. try using 


```
Private PathShared As String = Environ("tmp") & "\server"
```

----------


## Joke Sparrow

thank you for your reply but the same error..

----------


## CVMichael

What IS the error then ?

----------

