Results 1 to 3 of 3

Thread: Winsock Control over internet

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    71

    Winsock Control over internet

    Hello everybody

    i want to connect to web server using winsock control.is this possible.also if my client is connecting through proxy server then how can winsock connect through proxy server.plz help

    parth

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Winsock Control over internet

    Moved to network programming...

  3. #3
    New Member
    Join Date
    Oct 2005
    Posts
    3

    Re: Winsock Control over internet

    Dunno about using a proxy server sorry, but without considering proxies, this is how you can download a webpage from your program:

    Say on a form you make a text box (Text1), a command button (Command1) and a winsock object (Winsock1). Something like this would download a page when you click the button and display the source into the text box.

    VB Code:
    1. Private Sub Command1_Click()
    2.     Winsock1.RemoteHost = "www.vbforums.com" 'domain of website
    3.     Winsock1.RemotePort = 80 'websites use port 80
    4.     Winsock1.LocalPort = 0 'just leave this at 0 (I think it means it auto assigns or something,
    5.                            'I forget now. A long time since I done this)
    6.     Winsock1.Connect 'connect to host
    7. End Sub
    8.  
    9. Private Sub Winsock1_Connect()
    10.     'request the file you want to download from the website including its path.
    11.     'you need the two vbCrLf, they are just some kinda thing that the web
    12.     'server expects from the client to signal the end of the request.
    13.     Winsock1.SendData "GET /game/score.asp HTTP/1.0" & vbCrLf & vbCrLf
    14. End Sub
    15.  
    16.  
    17. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    18.     Winsock1.GetData rdata, vbString 'receive the packet and store it into rdata
    19.     Text1.Text = Text1.Text & rdata 'append the text that was just received
    20.                                     'onto the end of the content of the text box
    21. End Sub

    Hope this helps you make a start. Note that the url used in my example there is invalid, put in your own URL and give it a try. At some stage, you need to close your socket too, but don't do it right after it's received a packet, else it will prevent further packets from coming in (ie. the other chunks of source code as it is being sent bit by bit). The command for this would be Winsock1.Close.
    Last edited by Reiko; Oct 19th, 2005 at 11:27 AM.

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