Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Can Php Interact With A Visual Basic App On A Server
it01y2
post Nov 14 2006, 08:51 PM
Post #1


Member [Level 1]
****

Group: Members
Posts: 65
Joined: 7-July 05
Member No.: 9,139



I am currently making a game. And I want to use a command through php to ineract with a visual basic app on my server. Is it possible? and how?
Go to the top of the page
 
+Quote Post
ghostrider
post Nov 14 2006, 11:16 PM
Post #2


Super Member
*********

Group: Members
Posts: 397
Joined: 9-June 06
From: Wisconsin
Member No.: 24,924



I've been programming in VB for ten years, can you describe what you are trying to do with a little more detail? I think it is possible to do. PM me or post back and I'll help you out.
Go to the top of the page
 
+Quote Post
Plenoptic
post Nov 15 2006, 01:49 AM
Post #3


Trap Double Mocha Member
***************

Group: [HOSTED]
Posts: 2,228
Joined: 5-November 05
From: That one place over there...
Member No.: 13,830



I was pretty sure that only ASP can interact with Visual Basic which would mean no unless you have a Windows Server for your hosting that supports ASP. I don't know really though I'm still relatively new to Visual Basic. Last I knew though it was only ASP.
Go to the top of the page
 
+Quote Post
ghostrider
post Nov 15 2006, 03:28 AM
Post #4


Super Member
*********

Group: Members
Posts: 397
Joined: 9-June 06
From: Wisconsin
Member No.: 24,924



If what I think he is thinking about is right, its a simple enough concept. This is how I would approach it.

1. The PHP program writes some data to a file in some format.
2. The VB program constantly sees if a file is there for it to read.
3. The VB program processes it and puts the result back in another file.
4. The VB program deletes the original file. (so that the PHP program can create a new one later)
5. The PHP program opens the file the VB program wrote, and has the results.
6. The PHP program deletes the file.

Another way I could see this working is using a Winsock control in the VB program, and then using the socket functions of PHP to connect to it and process the request. This technique seems more practical now that I think about it. Here is how I would write this one.

1. The VB program is constantly listening for connections.
2. The PHP program connects to the IP address 127.0.0.1 (your computers IP) or localhost
3. The PHP program sends what needs to be done to the VB one.
4. The VB program returns the data and closes the connection.

The technique I wrote above seems more practical because it can handle multiple requests, instead of just one file. It probably is slightly faster (by a very small amount) because the computer doesn't need to write to the hard disk constantly.

The opposite, using VB and calling a PHP program can be done. I am currently writing a game that will use this technique for match making. It works like this.

1. You have a PHP program that does a certain function and accepts its data through GET

CODE

<?PHP
$variable = $_GET['mode'];
// if you have the url, http://www.whateversite.com/phpprogram.php?mode=1, the $variable = 1.
PHP?>


2. The VB program uses the Inet control, and sends the request.
3. The PHP program would output its result using the print() or echo() variable.


I hope this helps you guys out a lot. I'll be happy to guide you along and answer any other questions you have.
Go to the top of the page
 
+Quote Post
matak
post Jan 16 2007, 09:06 PM
Post #5


Super Member
*********

Group: Members
Posts: 413
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



You might find this question strange, but well, i'm a noob.. So it is possible to write programs in C, VB, put them on server and make them "work" and intereact to PHP ?!
Any good tutorials on that, or any good simple free programs that do the same? (open source possibly...)
Go to the top of the page
 
+Quote Post
QuickSilva
post Jan 17 2007, 04:56 PM
Post #6


Premium Member
********

Group: Members
Posts: 181
Joined: 15-January 07
From: Rotherham, UK
Member No.: 37,245



I also thought ASP was the only language that could interact with VB. I may be mistaken though.

Have a great day!

-Tom.
Go to the top of the page
 
+Quote Post
Galahad
post Jan 30 2007, 06:34 PM
Post #7


Neurotical Squirrel
*********

Group: [HOSTED]
Posts: 590
Joined: 4-November 04
From: Novi Sad, Vojvodina
Member No.: 2,127



ASP is written in a language that has BASIC as it's foundation...

Traditionaly, Microsoft IIS web server, was used to host ASP pages, and Apache was used to host PHP pages... There is a plugin (or module) for IIS and PWS that allows processing of PHP, but it's not that good, and it is very limiting in power, i believe PHP works only in CGI mode... Anyways, not to stray from the topic...

There are few ways to connect VB with PHP scripts...

Least efficient is through file, as ghostrider said... It's inefficient, since it consumes much CPU time, and thus we'll forget about it (I tried similar approach once, for connecting VB program, with QB program... Not good)

Second method is by using MySQL for exchange of information... Connect VB to MySQL server, connect PHP script to MySQL server, and voila... Easy setup of information... This could be a good method, I'm using it for displaying some info on my site... May be non-efficient though, if too frequent queries should occur...

Third method, again mentioned by ghostrider, involves using socket functions of PHP, to connect it directly to your VB application... A good method, probably the best option... The second part of it, transmitting data to PHP script, I would use POST method, not GET... First, GET metod has a limitation to its length (2K I believe), and POST is used to transfer large quantities of data...

Here, I'm including code used to send data via POST methid, using Microsoft Internet Controls OCX... Just add it to your project, and use the following code:

CODE
Public Sub SendData(ByRef wb As WebBrowser, ByVal Params As String)
Dim vPost     As Variant
Dim vFlags    As Variant
Dim vTarget   As Variant
Dim vHeaders  As Variant
Dim aByte()   As Byte
Dim i         As Long

' Params are in the following format <param-name>=<param-value>[&<param-name>=<param-value>[&...]]
PackBytes aByte(), Params
vPost = aByte
vFlags = &H2 Or &H4 Or &H8 Or &H10
vHeaders = "(anti-spam-(anti-spam-content-type:)) application/x-www-form-urlencoded" & vbCrLf
wb.Navigate "http://your-server/php-script.php", vFlags, vTarget, vPost, vHeaders
End Sub

Private Sub PackBytes(ByRef ByteArray() As Byte, ByVal PostData As String)
Dim i As Long
Dim j As Long
Dim c As String

j = Len(PostData) - 1
If j < 0 Then
Exit Sub
End If
ReDim ByteArray(j)
For i = 0 To j
c = Mid(PostData, i + 1, 1)
If c = Space(1) Then
    c = "+"
End If
ByteArray(i) = Asc(c)
Next
End Sub


This code is sure to send data to your script, via POST methid. You can ofcourse parse resulting webpage, and control your VB application taht way too...

If you want, I can send you a DLL that you can use to connect with MySQL server, and read and write do MySQL databases, just PM me...

Hope this helped a bit...

Oh yeah, just remembered... Since Apache works (mostly, and preferably) on Linux, and VB applications can't do that (sadly laugh.gif), and I'm sure you won't be setting up PHP support on IIS or PWS, your applicayion would have to run on a separate server, running Windows, probably the best method would be to use combination of socket functions in PHP, and, depending on update rate you need, MySQL, or POST method of returning data to your script...

Cheers smile.gif
Go to the top of the page
 
+Quote Post
matak
post Jan 31 2007, 02:51 AM
Post #8


Super Member
*********

Group: Members
Posts: 413
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



QUOTE(Galahad)
Oh yeah, just remembered... Since Apache works (mostly, and preferably) on Linux, and VB applications can't do that


i'm kinda noob programmer, but i found this post very interesting. i didn't remember that VB aps can be run only in windows environment so i posted this question. i won't learn Vb but C and C++ since it can be compiled both for linux and windows environments.
My logic suggests me that C programs could be written to interact with php, and it's kinda logical couse php is written in C (i guess). So if at any time of my life i want to make an application in C to interact with PHP what would be the right way to do that!? It is so soon to talk about that for me, but you don't need to answer right now, and maybe there is more ppl interested in this subject so you could writte anyway.
What is the difference between running PHP as Module or as CGI script, how is all of that conected with basic root program of PHP (what is root program of PHP, how can i start modifiying php, and is it smart to do that, just for fun, and for learning purposes)
thanks
Go to the top of the page
 
+Quote Post
farsiscript
post Jan 31 2007, 07:06 AM
Post #9


Super Member
*********

Group: Members
Posts: 357
Joined: 8-April 06
Member No.: 21,487



Dear it01y2 You can transfer Data between VisualBasic and PHP via URL Like this :
CODE
$Somen