Winsock connecting to Internet 
Author Message
 Winsock connecting to Internet

I'm writing a VB5 application that sits between a browser and the internet.
My environment is a LAN with MS Proxy Server connecting us to the WWW.
My application has two Winsock control arrays. One is in "listen" mode
waiting for the browser to request a connection at which point it loads a
new instance of the Winsock control and accepts the connection. This works
fine:

Private Sub sckBrowser_ConnectionRequest(Index As Integer, ByVal RequestID
As Long)

<snip>

If Index = 0 Then

    ' increment browser count
    intBrowserCount = intBrowserCount + 1

    ' create a new browser socket instance.
    Load sckBrowser(intBrowserCount)
    sckBrowser(intBrowserCount).Close
    sckBrowser(intBrowserCount).LocalPort = 327
    sckBrowser(intBrowserCount).Accept RequestID

End If

etc

I've got the socket set to an arbitrary port (327) which I set up the
browser to connect through.

The other initiates a connection to the Proxy:

    ' create a new socket instance
    Load sckWWW(intBrowserCount)
    sckWWW(intBrowserCount).Close
    sckWWW(intBrowserCount).LocalPort = 0
    sckWWW(intBrowserCount).RemoteHost = "NTSERVER"
    sckWWW(intBrowserCount).RemotePort = 80
    sckWWW(intBrowserCount).Connect

I then basically display the data from each socket in a listbox, then pass
on the data on between the two sockets.
This works reasonably well except for two problems (which is why I'm posting
this message):

1. The browser (I'm using IE4) seems to initiate multiple connection
requests for the one URL. This isn't a big problem because the data ends up
at the same browser, it's just that some web pages may have 4 or 5 socket
connections. I need someway to manage (or eliminate) these multiple
connections. I'd like to basically ignore the multiple connection requests
so that each browser has just one connection.

2. The connection to the Web (via MS Proxy Server) stays open while there is
no activity. Once I start sending the browser requests (HTTP) through, the
proxy responds with the corresponding data, then without warning, it closes
the connection (even though the request may still be processing). This is
causing a major problem. I can tell the socket control to reconnect in the
close event, but that is pointless because now it's a new connection and it
won't get the previously requested data. The browser connection also closes
without warning at times.

Can anyone help?

Matthew Bryde



Sun, 07 May 2000 03:00:00 GMT  
 Winsock connecting to Internet

I just finished reading a primer on HTTP and discovered that a browser may
open up to 4 connections per page. It first requests the page (as text only)
then scans the HTML for references to graphic file and may then request a
new connection to retrieve the graphic. At this point the server may have
already closed the previous connection.

The solution therefore, is to redesign the app to handle closing each
connection after a server response. Of course I have a new problem :)

I need to open a new connection to the server each time I get a request from
the browser. I can "load" a new instance of the server Winsock control in
the ConnectionRequest event of the browser Winsock control, but the problem
is that immediately on exit, the DataArrival event is fired which want to
relay the data onto the server Winsock control, which may still be in the
process of connecting. I don't really want to insert some form of delay here
as this delay may be interrupted by another ConnectionRequest (and hence
DataArrival) Event. Also I don't want to do something like: "do while
sckWWW(Index).state <> sckConnected" in case an error occurs and I'm left
with an infinite loop (very BAD programming)

SO....The original problem below is solved, but a new problem now exists.

Anyone?

Matthew Bryde

Quote:

>I'm writing a VB5 application that sits between a browser and the internet.
>My environment is a LAN with MS Proxy Server connecting us to the WWW.
>My application has two Winsock control arrays. One is in "listen" mode
>waiting for the browser to request a connection at which point it loads a
>new instance of the Winsock control and accepts the connection. This works
>fine:

>Private Sub sckBrowser_ConnectionRequest(Index As Integer, ByVal RequestID
>As Long)

><snip>

>If Index = 0 Then

>    ' increment browser count
>    intBrowserCount = intBrowserCount + 1

>    ' create a new browser socket instance.
>    Load sckBrowser(intBrowserCount)
>    sckBrowser(intBrowserCount).Close
>    sckBrowser(intBrowserCount).LocalPort = 327
>    sckBrowser(intBrowserCount).Accept RequestID

>End If

>etc

>I've got the socket set to an arbitrary port (327) which I set up the
>browser to connect through.

>The other initiates a connection to the Proxy:

>    ' create a new socket instance
>    Load sckWWW(intBrowserCount)
>    sckWWW(intBrowserCount).Close
>    sckWWW(intBrowserCount).LocalPort = 0
>    sckWWW(intBrowserCount).RemoteHost = "NTSERVER"
>    sckWWW(intBrowserCount).RemotePort = 80
>    sckWWW(intBrowserCount).Connect

>I then basically display the data from each socket in a listbox, then pass
>on the data on between the two sockets.
>This works reasonably well except for two problems (which is why I'm
posting
>this message):

>1. The browser (I'm using IE4) seems to initiate multiple connection
>requests for the one URL. This isn't a big problem because the data ends up
>at the same browser, it's just that some web pages may have 4 or 5 socket
>connections. I need someway to manage (or eliminate) these multiple
>connections. I'd like to basically ignore the multiple connection requests
>so that each browser has just one connection.

>2. The connection to the Web (via MS Proxy Server) stays open while there
is
>no activity. Once I start sending the browser requests (HTTP) through, the
>proxy responds with the corresponding data, then without warning, it closes
>the connection (even though the request may still be processing). This is
>causing a major problem. I can tell the socket control to reconnect in the
>close event, but that is pointless because now it's a new connection and it
>won't get the previously requested data. The browser connection also closes
>without warning at times.

>Can anyone help?

>Matthew Bryde




Mon, 08 May 2000 03:00:00 GMT  
 Winsock connecting to Internet

OK :)

I've now solved the problem below by getting the data from socket and adding
it to a UDT. Then in a timer, I check if the corresponding socket's State =
sckConnected before trying to send.

A new problem: When the browser requests a page, it seems to download most
of the page except a few graphics. It then just seems to pause (with IE
globe spinning) indefinitely.

Is there some HTTP string that the web server sends to the browser to tell
it the page is now complete?

Quote:

>I just finished reading a primer on HTTP and discovered that a browser may
>open up to 4 connections per page. It first requests the page (as text
only)
>then scans the HTML for references to graphic file and may then request a
>new connection to retrieve the graphic. At this point the server may have
>already closed the previous connection.

>The solution therefore, is to redesign the app to handle closing each
>connection after a server response. Of course I have a new problem :)

>I need to open a new connection to the server each time I get a request
from
>the browser. I can "load" a new instance of the server Winsock control in
>the ConnectionRequest event of the browser Winsock control, but the problem
>is that immediately on exit, the DataArrival event is fired which want to
>relay the data onto the server Winsock control, which may still be in the
>process of connecting. I don't really want to insert some form of delay
here
>as this delay may be interrupted by another ConnectionRequest (and hence
>DataArrival) Event. Also I don't want to do something like: "do while
>sckWWW(Index).state <> sckConnected" in case an error occurs and I'm left
>with an infinite loop (very BAD programming)

>SO....The original problem below is solved, but a new problem now exists.

>Anyone?

>Matthew Bryde


>>I'm writing a VB5 application that sits between a browser and the
internet.
>>My environment is a LAN with MS Proxy Server connecting us to the WWW.
>>My application has two Winsock control arrays. One is in "listen" mode
>>waiting for the browser to request a connection at which point it loads a
>>new instance of the Winsock control and accepts the connection. This works
>>fine:

>>Private Sub sckBrowser_ConnectionRequest(Index As Integer, ByVal RequestID
>>As Long)

>><snip>

>>If Index = 0 Then

>>    ' increment browser count
>>    intBrowserCount = intBrowserCount + 1

>>    ' create a new browser socket instance.
>>    Load sckBrowser(intBrowserCount)
>>    sckBrowser(intBrowserCount).Close
>>    sckBrowser(intBrowserCount).LocalPort = 327
>>    sckBrowser(intBrowserCount).Accept RequestID

>>End If

>>etc

>>I've got the socket set to an arbitrary port (327) which I set up the
>>browser to connect through.

>>The other initiates a connection to the Proxy:

>>    ' create a new socket instance
>>    Load sckWWW(intBrowserCount)
>>    sckWWW(intBrowserCount).Close
>>    sckWWW(intBrowserCount).LocalPort = 0
>>    sckWWW(intBrowserCount).RemoteHost = "NTSERVER"
>>    sckWWW(intBrowserCount).RemotePort = 80
>>    sckWWW(intBrowserCount).Connect

>>I then basically display the data from each socket in a listbox, then pass
>>on the data on between the two sockets.
>>This works reasonably well except for two problems (which is why I'm
>posting
>>this message):

>>1. The browser (I'm using IE4) seems to initiate multiple connection
>>requests for the one URL. This isn't a big problem because the data ends
up
>>at the same browser, it's just that some web pages may have 4 or 5 socket
>>connections. I need someway to manage (or eliminate) these multiple
>>connections. I'd like to basically ignore the multiple connection requests
>>so that each browser has just one connection.

>>2. The connection to the Web (via MS Proxy Server) stays open while there
>is
>>no activity. Once I start sending the browser requests (HTTP) through, the
>>proxy responds with the corresponding data, then without warning, it
closes
>>the connection (even though the request may still be processing). This is
>>causing a major problem. I can tell the socket control to reconnect in the
>>close event, but that is pointless because now it's a new connection and
it
>>won't get the previously requested data. The browser connection also
closes
>>without warning at times.

>>Can anyone help?

>>Matthew Bryde




Tue, 09 May 2000 03:00:00 GMT  
 Winsock connecting to Internet

I do not believe that you will be able to eliminate the multiple
connections from the browser.  The browser is trying to get as much from as
many places as possible all at once.  If it is possible, you will need to
"manage" the connections.



Quote:
> I'm writing a VB5 application that sits between a browser and the
internet.
> My environment is a LAN with MS Proxy Server connecting us to the WWW.
> My application has two Winsock control arrays. One is in "listen" mode
> waiting for the browser to request a connection at which point it loads a
> new instance of the Winsock control and accepts the connection. This
works
> fine:

> Private Sub sckBrowser_ConnectionRequest(Index As Integer, ByVal
RequestID
> As Long)

> <snip>

> If Index = 0 Then

>     ' increment browser count
>     intBrowserCount = intBrowserCount + 1

>     ' create a new browser socket instance.
>     Load sckBrowser(intBrowserCount)
>     sckBrowser(intBrowserCount).Close
>     sckBrowser(intBrowserCount).LocalPort = 327
>     sckBrowser(intBrowserCount).Accept RequestID

> End If

> etc

> I've got the socket set to an arbitrary port (327) which I set up the
> browser to connect through.

> The other initiates a connection to the Proxy:

>     ' create a new socket instance
>     Load sckWWW(intBrowserCount)
>     sckWWW(intBrowserCount).Close
>     sckWWW(intBrowserCount).LocalPort = 0
>     sckWWW(intBrowserCount).RemoteHost = "NTSERVER"
>     sckWWW(intBrowserCount).RemotePort = 80
>     sckWWW(intBrowserCount).Connect

> I then basically display the data from each socket in a listbox, then
pass
> on the data on between the two sockets.
> This works reasonably well except for two problems (which is why I'm
posting
> this message):

> 1. The browser (I'm using IE4) seems to initiate multiple connection
> requests for the one URL. This isn't a big problem because the data ends
up
> at the same browser, it's just that some web pages may have 4 or 5 socket
> connections. I need someway to manage (or eliminate) these multiple
> connections. I'd like to basically ignore the multiple connection
requests
> so that each browser has just one connection.

> 2. The connection to the Web (via MS Proxy Server) stays open while there
is
> no activity. Once I start sending the browser requests (HTTP) through,
the
> proxy responds with the corresponding data, then without warning, it
closes
> the connection (even though the request may still be processing). This is
> causing a major problem. I can tell the socket control to reconnect in
the
> close event, but that is pointless because now it's a new connection and
it
> won't get the previously requested data. The browser connection also
closes
> without warning at times.

> Can anyone help?

> Matthew Bryde




Tue, 09 May 2000 03:00:00 GMT  
 Winsock connecting to Internet

OK, I have yet another problem with the Winsock control:

Private Sub sckWWW_DataArrival(Index As Integer, ByVal bytesTotal As Long)

    Dim strData As String

    sckWWW(Index).GetData strData, vbString, bytesTotal

I get an error on that last line, saying "Wrong protocol or connection state
for the requested transaction or request". In other words, the "Index"
instance of the socket is no longer in the "sckConnected" state, and yet the
"DataArrival" event was just fired. This make absolutely no sense.

I could add the line:     "If sckWWW(Index).State = sckConnected Then"
before the last line to avoid the error, but (besides being a stupid thing
to have to do) what then happens to the data that actually fired the
DataArrival Event in the first place?? I guess I lose it, permanently, which
is unacceptable.

Once again, HELP!

Matthew Bryde

Quote:

>I'm writing a VB5 application that sits between a browser and the internet.

etc etc


Fri, 12 May 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Winsock connecting to Internet

2. How to use winsock to connect with internet

3. Connect to private IP via Internet using Winsock?

4. Winsock newbie - connect to internet

5. Winsock Control Not Connecting and Staying in Status 6 (Connecting)

6. Using Winsock control to connect to C#

7. Multiple Winsock Connect and Disconnect

8. Winsock Connect problem

9. Winsock (Re-)Connect-Error

10. Help with Winsock Connecting

11. Winsock won't connect

12. Winsock - connecting to a Unix box question

 

 
Powered by phpBB® Forum Software