Use VB to initiate a socket connection to PHP.

I have a VB program that I would like to talk to my webserver. The catch is, I want the VB program to initiate the connection. I am sure I have to use socket programming, but I don't know how to do it. Can you guys help?
LVL 32
DrDamnitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geir_andersenSystems engineerCommented:
I think your best bet is to post this question, or a pointer, in the VB section of Programming:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/

-Geir
DrDamnitAuthor Commented:
To be more clear: I am unclear on how to get PHP to listen, and also how to process requests that it recieves.
alain34Commented:
this function will enable you to send an http request by using msxml!!!

Function sendRequest$(url$, method$, content$)

'using XMLHttp in msxml3
Dim oHttp As XMLHTTP          'the client object
Dim strURL As String          'URL to be pulled
Dim mstrResponse As String
Dim aBytes() As Byte
Dim nbByte, i As Integer
Dim File      As String
Dim texte      As String

Dim timeStart As Date
Dim timeCurrent As Date
Dim timeOut As Boolean
Dim endLoop As Boolean

'create HTTP client
'On Error Resume Next
Set oHttp = CreateObject("msxml2.xmlhttp")         'for use on client
If oHttp Is Nothing Then
   MsgBox "Msxml 3.0 is not installed. You may download it from msdn.microsoft.com/xml", vbCritical
   Exit Function
End If

'get
'DoEvents
oHttp.open method$, url$, True
oHttp.setRequestHeader "Content-Type ", "application/octet-stream"
If method$ = "GET" Then
   oHttp.send
Else
   oHttp.send (content$)
End If

timeStart = Now
timeOut = False
endLoop = False
While endLoop = False
DoEvents
timeCurrent = Now - TimeSerial(0, 0, 30)
If timeCurrent > timeStart Then
   timeOut = True
   endLoop = True
Else
   If oHttp.readyState = 4 Then
      endLoop = True
   End If
End If
Wend

If timeOut = True Then
   sendRequest$ = False
Else
   mstrResponse = ""
   If Len(oHttp.responseBody) > 0 Then
      aBytes = oHttp.responseBody

      File = App.Path & "\" & App.Title & ".tmp"
      Open File For Binary As #1
      Put #1, , aBytes
      Close

      Open File For Binary As #1
      Put #1, , aBytes
      Close

      Open File For Input As #1
      Do While Not EOF(1)
         Line Input #1, texte
         mstrResponse = mstrResponse & texte & vbCrLf
      Loop
      Close #1

      Kill File
      'beautify output
      sendRequest$ = Replace(mstrResponse, vbLf, vbCrLf)
   Else
      sendRequest$ = False
   End If
 
End If

End Function
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

alain34Commented:
if you use the method that I have describe, you are not using socket programming on the VB side, you are simulating a browser connection, therefore your php program does not need to listne for socket or doing anything different that for a request coming from a browser!
DrDamnitAuthor Commented:
Well, the whole point is so that I can have PHP query MySQL since my hosting provider doens't allow direct access to MySQL. Moreovre, I had a web interface to manage the data in the database, so I don't need to do anything more than that. I just need a reliable connection. Will the code above work even though it is not a socket connection?
alain34Commented:
yes it will

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.