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
Printable View
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
Moved to network programming...
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:
Private Sub Command1_Click() Winsock1.RemoteHost = "www.vbforums.com" 'domain of website Winsock1.RemotePort = 80 'websites use port 80 Winsock1.LocalPort = 0 'just leave this at 0 (I think it means it auto assigns or something, 'I forget now. A long time since I done this) Winsock1.Connect 'connect to host End Sub Private Sub Winsock1_Connect() 'request the file you want to download from the website including its path. 'you need the two vbCrLf, they are just some kinda thing that the web 'server expects from the client to signal the end of the request. Winsock1.SendData "GET /game/score.asp HTTP/1.0" & vbCrLf & vbCrLf End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Winsock1.GetData rdata, vbString 'receive the packet and store it into rdata Text1.Text = Text1.Text & rdata 'append the text that was just received 'onto the end of the content of the text box 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.