Writing a simple webserver

Started by
16 comments, last by daerid 19 years ago
I've been thinking about making a very simple webserver. I can't seem to get it working. (in vb). Mozilla isn't sending any requests. It connects, then it just times out. (and says 'the document contains no data'. I connect to telnet, and it just pops up with a 'connection to host lost' thing basically instantly. Does anybody have any information that can shed some light in it? I currently have two winsock controls and come really basic debugging code.

Private Sub Form_Load()
Winsock1.Listen
Me.Hide
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Connect requestID
'Winsock2.Connect requestID
DoEvents
End Sub

Private Sub Winsock2_Connect()
Debug.Print "Winsock2 connected"
End Sub

Private Sub Winsock2_ConnectionRequest(ByVal requestID As Long)
Debug.Print requestID
End Sub

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Winsock1.GetData s, vbString, bytesTotal
Debug.Print s
End Sub

I've tried everything i can think of, but it just isn't connecting! ARGGG! From, Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Advertisement
Hi,

I think it times out, because you aren't replying on the request.
It sends GET .... and is waiting for an answer, the html document.
In your code there is no reply function.

Marc
It doesn't particularly matter, because:

1. It times out instantly. (it doesn't do anything. Even when i connect via telnet, it looses connection instantly) and

2. It isn't connecting. At all. It goes through the connection code, but it doesn't connect.

and

3. It isn't recieving any data. At all.

From,
nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
I haven't written any VB networking code in a long time, but shouldn't you be calling

Winsock1.accept requestID


in Winsock1_ConnectionRequest, rather than Winsock1.Connect? Also, have you set the port number to be listening on? In code you could write

Winsock1.LocalPort = 80


Just before calling Winsock1.Listen.

Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
If you don't mind looking a few examples...
Link 1 | Link 2 | Link 3 | Link 4

Now after 5 views of code, you will have to register, but that site is the best [grin]. See if any of those can help you figre out what the problem is.
Quote:Original post by Alan Kemp
I haven't written any VB networking code in a long time, but shouldn't you be calling

*** Source Snippet Removed ***

in Winsock1_ConnectionRequest, rather than Winsock1.Connect? Also, have you set the port number to be listening on? In code you could write

*** Source Snippet Removed ***

Just before calling Winsock1.Listen.

Alan


Spoke too soon.
It recieves the request, but mozilla isn't doing anything. (it times out)

Rate++ anyway

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Quote:Original post by Drew_Benton
If you don't mind looking a few examples...
Link 1 | Link 2 | Link 3 | Link 4

Now after 5 views of code, you will have to register, but that site is the best [grin]. See if any of those can help you figre out what the problem is.


Thanks. I've already seen planetsourcecode. (and i have an account, assuming they haven't gotten rid of it.)

Now, does anybody have any idea on how to send things like images, ect?

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Ok, its working. (thanks drew :) i needed those egsamples. Turns out i was missing a doevents before i was closing the socket).

Now, how would i do images?

From,
nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Ok, it works now. (with images, and 404's :))

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Got directory listings to work.

<html><head><title>Directory list of /Web</title></head>Directory listing of /Web<br>Made by Armada Server<hr>Directories: <hr><a href='Web/Folder'>Folder</a><br><hr> Files <hr> <a href='Web/Something.txt'>Something.txt</a><br><a href='Web/Somethingelse.txt'>Somethingelse.txt</a><br>


Looks really good :).

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.

This topic is closed to new replies.

Advertisement