|
-
May 22nd, 2007, 03:26 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Networking with Winsock, webserver code return.
Ok here's what I'm doing it's not complicated if you know Winsock.
Im using a hosts file in my app to block the adverts, and as you know to do this I redirect ad servers to 127.0.0.1. This is not a problem and I can block the ads successfully.
I want to make a vb6 file to listen on port 80 of 127.0.0.1 (itself) and then when it gets a get request simply return the page BLOCK.HTM at C:\
Why?
The Hosts file redirects to loopback/localhost. At localhost I want to run a webpage (block.htm) so that when an ad is in the browser, it displays block.htm where I can write that an advert was blocked. .See?
I would use index.html but WebServer 2.0 (see above) does not have default starting pages.
I hope you can see now. I can already handle the popup blocking, I simply want to make a project with a winsock control so that I can respond to requests on 127.0.0.1 instead of HOSTS returning a page cannot be displayed. This will be an efficient way of showing the user an ad was blocked and I will be able to give them options to see page anyway.
Basically in WebServer 2.0, it returns the page depending on your query string. Any web server does, for example, If I sent www.blahblah.com/hey.asp to an IIS server it would respond with c:\inetpub\hey.asp (example), because I cannot specify urls in hosts file. I want it so that 127.0.0.1/ or 127.0.0.1/whateveriswrittenhere always returns the page Block.htm
So somethng like
(SECURITY IMPLEMENTATION) NO ACCESS TO OUT OF ROOT)
If rData like *get* blah, etc...
then *GET BLOCK.HTM
I just don't get this last bit.
Anyone please help?
Last edited by samtheman; May 22nd, 2007 at 04:15 PM.
-
May 22nd, 2007, 03:29 PM
#2
Lively Member
Re: Yeah
You need to change the title to be a little bit more code specific, i'll see what i can come up with
-
May 22nd, 2007, 03:57 PM
#3
Lively Member
Last edited by ixtrip; May 22nd, 2007 at 04:20 PM.
-
May 22nd, 2007, 04:02 PM
#4
Thread Starter
Hyperactive Member
Re: Yeah
Sorry, doesn't work. I don't think the application is responding to the listening. I noticed you placed to read the HTML in a function. But that function is never called?
Edit: forgot to say, thanks so much for the effort.
2'nd Edit: It looks like its sort of working get 'Website Found' in StatusBar but nothing else. I see the function is called but don't you need to send a SERVER 200 message with the Get feature.
Last edited by samtheman; May 22nd, 2007 at 04:06 PM.
-
May 22nd, 2007, 04:06 PM
#5
Lively Member
Re: Yeah
hm you're right...i had it working for a minute, must have been something i changed and was probably just loading the cache, let me bug it out
-
May 22nd, 2007, 04:14 PM
#6
Re: Yeah
@samtheman:
is it possible that you change this topic's title to be more meaningful? Thanks.
-
May 22nd, 2007, 04:15 PM
#7
Thread Starter
Hyperactive Member
Re: Networking with Winsock, webserver code return.
I am sorry I thought I was replying to a thread but accidentally made a new one, changed title now. Thanks.
-
May 22nd, 2007, 04:21 PM
#8
Lively Member
Re: Networking with Winsock, webserver code return.
vb Code:
Dim CurrentConnection As Integer
Dim HTML1
Private Sub Winsock1_Close(Index As Integer)
Winsock1(Index).Close
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
CurrentConnection = CurrentConnection + 1
Load Winsock1(CurrentConnection)
If Winsock1(CurrentConnection).State = sckClosed Then Winsock1(CurrentConnection).Close
Winsock1(CurrentConnection).Accept (requestID)
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
GetWEBPAGE
Winsock1(CurrentConnection).SendData HTML1
End Sub
Private Sub Winsock1_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Winsock1(Index).Close
End Sub
Private Sub Winsock1_SendComplete(Index As Integer)
Winsock1(Index).Close
End Sub
Private Sub Command1_Click()
Winsock1(CurrentConnection).LocalPort = "80"
Winsock1(CurrentConnection).Listen
End Sub
Public Function GetWEBPAGE()
Dim fFile As Integer
Dim Data As String
fFile = FreeFile
Open "c:\test.html" For Binary As #fFile
Data = String(FileLen("c:\test.html"), " ")
Get #fFile, , Data
HTML1 = Data
End Function
Private Sub Command2_Click()
For i = 0 To CurrentConnection
Winsock1(i).Close
Next i
End Sub
-
May 22nd, 2007, 04:22 PM
#9
Thread Starter
Hyperactive Member
Re: Networking with Winsock, webserver code return.
you can post project? because i cant copy and paste vbcode comes out in word wrap format.
thks
-
May 22nd, 2007, 04:24 PM
#10
Lively Member
Re: Networking with Winsock, webserver code return.
-
May 22nd, 2007, 04:27 PM
#11
Thread Starter
Hyperactive Member
Re: Networking with Winsock, webserver code return.
THANK YOU SO MUCH!!!!!!!!!
lol sorry bout caps.
again thank you for your effort and support.
-
May 22nd, 2007, 04:35 PM
#12
Lively Member
Re: Networking with Winsock, webserver code return.
No Problem ;-)
If that worked, please change the title to
[RESOLVED] in the front.
Thanks!
-
May 22nd, 2007, 04:57 PM
#13
Re: Networking with Winsock, webserver code return.
Just a few suggestions and possible bugs in that program above
- HTML1 is of variant data type
- GetWEBPAGE function is used in the way a sub should be used. It returns nothhing and the return type is of variant
- Line9: you're saying if its closed then close it. I'd replace this with Winsock().close because a connection cannot be accepted without it being closed, no need for any if statement.
- Line 26: no need for quotes around an integer, they are for string literals
- Line 25: ALWAYS close the socket before trying to listen
- Biggest problem: The program creates a new socket each time a client connects, if this app is ran for a long period of time it will crash after a certain point, and it will eat the system ram, imagine running it for 1day and get say 15 connections, thats 15 loaded unused sockets, imagine it after a week.
What should be happening is when a connection is made, CHECK if there is any available sockets to use, if yes accept the connection on that socket, if not, load a new one up. Thats the procedure it should take. Do not load a new socket up upon every request unless absolutely required.
One more thing, if this is only going to run on one computer locally, whats the need for multiple clients?
-
May 22nd, 2007, 05:09 PM
#14
Lively Member
Re: [RESOLVED] Networking with Winsock, webserver code return.
Yeah thanks for the input on it i see exactly what you mean, it was just something quick, and i wasn't sure how many connections he was gonna have that's why there's an array. It wouldn't be hard to modify it to fix all that, just givin him somewhere to start, not gonna do the whole thing myself :-D
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|