Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Communications > Webclient and Server Handshake


Reply
 
Thread Tools Display Modes
  #1  
Old 05-21-2007, 04:43 PM
AgentSmithers AgentSmithers is offline
Contributor
 
Join Date: Jan 2005
Location: SOCal
Posts: 492
Default Webclient and Server Handshake


Well what im confused on is Im using winsock as a Webclient and using textboxes to send and recive Commands to and from a web server so far I got something like this..

Code:
Private Sub Form_Load()
Winsock1.LocalPort = 80
Winsock1.Connect "72.14.207.99", 80
End Sub

Private Sub Winsock1_Close()
Text1.Text = Text1.Text & "Connection Closed" & vbCrLf
End Sub

Private Sub Winsock1_Connect()
Text1.Text = Text1.Text & "Connected " & vbCrLf
Winsock1.SendData Text2.Text
Text1.Text = Text1.Text & Text2.Text & vbCrLf
DoEvents
Winsock1.Close
Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData Data, vbString
Text1.Text = Text1.Text & Data & vbCrLf
End Sub
text2.text contains

GET / HTTP/1.1
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
Host: 127.0.0.1:8080
Connection: Keep-Alive



Host: 127.0.0.1:8080 <----- I think this needs to be edited, what does this need to be?

now All i want is good to send me their homepage index file.. what else needs to be done in order to do this?
Reply With Quote
  #2  
Old 05-22-2007, 04:40 AM
DougT's Avatar
DougT DougT is offline
Ultimate Antique

Administrator
* Expert *
 
Join Date: Sep 2005
Location: Maldon,Essex, UK
Posts: 3,939
Default

Well, a few things:
(1) Option Explicit in the Form Declaration Section
(2) If you're going to play with HTTP, then you'll need to look at the RFC (http://www.w3.org/Protocols/rfc2616/rfc2616.html)

Specifically, with your code you need to
(1) Indicate that you want index.html in the GET
(2) Indicate the Host you intend to get it from
(3) Terminate the request with two vbCrLfs
eg
Code:
Option Explicit Private Sub Form_Load() Text2.Text = "GET /index.html HTTP/1.1" & vbCrLf & _ "Host: www.google.com" & vbCrLf & vbCrLf Winsock1.RemotePort = 80 Winsock1.RemoteHost = "www.google.com" Winsock1.Connect End Sub Private Sub Winsock1_Close() Text1.Text = Text1.Text & "Connection Closed" & vbCrLf End Sub Private Sub Winsock1_Connect() Text1.Text = Text1.Text & "Connected " & vbCrLf Winsock1.SendData Text2.Text End Sub Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) Winsock1.Close Winsock1.Accept requestID End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim strData As String Winsock1.GetData strData, vbString Text1.Text = Text1.Text & strData End Sub
__________________
semel insanivimus omnes
S Data in context = Information, S Information in context = Knowledge, S Knowledge in context = Experience
S Experience in context = Wisdom= Data
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->