Results 1 to 14 of 14

Thread: [RESOLVED] Networking with Winsock, webserver code return.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    279

    Resolved [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.

  2. #2
    Lively Member ixtrip's Avatar
    Join Date
    Aug 2005
    Posts
    64

    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

  3. #3
    Lively Member ixtrip's Avatar
    Join Date
    Aug 2005
    Posts
    64

    Re: Yeah

    look below
    Last edited by ixtrip; May 22nd, 2007 at 04:20 PM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    279

    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.

  5. #5
    Lively Member ixtrip's Avatar
    Join Date
    Aug 2005
    Posts
    64

    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

  6. #6

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    279

    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.

  8. #8
    Lively Member ixtrip's Avatar
    Join Date
    Aug 2005
    Posts
    64

    Re: Networking with Winsock, webserver code return.

    vb Code:
    1. Dim CurrentConnection As Integer
    2. Dim HTML1
    3. Private Sub Winsock1_Close(Index As Integer)
    4. Winsock1(Index).Close
    5. End Sub
    6. Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    7.     CurrentConnection = CurrentConnection + 1
    8.         Load Winsock1(CurrentConnection)
    9.     If Winsock1(CurrentConnection).State = sckClosed Then Winsock1(CurrentConnection).Close
    10.     Winsock1(CurrentConnection).Accept (requestID)
    11. End Sub
    12.  
    13. Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    14.     GetWEBPAGE
    15.     Winsock1(CurrentConnection).SendData HTML1
    16. End Sub
    17.  
    18. 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)
    19.     Winsock1(Index).Close
    20. End Sub
    21.  
    22. Private Sub Winsock1_SendComplete(Index As Integer)
    23.     Winsock1(Index).Close
    24. End Sub
    25. Private Sub Command1_Click()
    26.     Winsock1(CurrentConnection).LocalPort = "80"
    27.     Winsock1(CurrentConnection).Listen
    28. End Sub
    29. Public Function GetWEBPAGE()
    30.  
    31.     Dim fFile As Integer
    32.     Dim Data As String
    33.     fFile = FreeFile
    34.     Open "c:\test.html" For Binary As #fFile
    35.     Data = String(FileLen("c:\test.html"), " ")
    36.     Get #fFile, , Data
    37.     HTML1 = Data
    38.  
    39. End Function
    40. Private Sub Command2_Click()
    41.     For i = 0 To CurrentConnection
    42.     Winsock1(i).Close
    43.     Next i
    44. End Sub

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    279

    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

  10. #10
    Lively Member ixtrip's Avatar
    Join Date
    Aug 2005
    Posts
    64

    Re: Networking with Winsock, webserver code return.


  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    279

    Re: Networking with Winsock, webserver code return.

    THANK YOU SO MUCH!!!!!!!!!

    lol sorry bout caps.

    again thank you for your effort and support.

  12. #12
    Lively Member ixtrip's Avatar
    Join Date
    Aug 2005
    Posts
    64

    Re: Networking with Winsock, webserver code return.

    No Problem ;-)

    If that worked, please change the title to

    [RESOLVED] in the front.

    Thanks!

  13. #13
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    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?
    Chris

  14. #14
    Lively Member ixtrip's Avatar
    Join Date
    Aug 2005
    Posts
    64

    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
  •  



Click Here to Expand Forum to Full Width