PHP UDP to VB6

What I am trying to do is simply have a PHP script send a UDP packet to a VB6 program.

I first setup a simple app to send and get data via IP addresses on 2 computers. It worked, but for some reason I could only get messages via UDP and my PC would not seem to send anything. My app actually posts data to a SQL server via PHP, so what I want to do is get the PHP script to send a reply to the post to all other users running the VB6 application.

I have this example here http://php.net/manual/en/function.socket-create.php and I have put my port number in, and my IP address, however, my VB6 application never sees any incomming packets, so I am out of ideas on what this could be. I know incomming worked from a VB6 to VB6 app, just not PHP to VB6.

I actually wonder if VB has any special headers needed to "see" incomming UDP packets on the set port ? This may be the problem, but I cannot find any information about packet headers sent in VB6.
exxos_ukAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

SwafnilCommented:
Could you give the following code a try? In case you have only used socket_create() and socket_connect(), nothing has been written to the socket so your VB application will not react.

Regards, Sascha
<?php
$vbhost = "localhost";
$port = 80; // or whatever port is listened on
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (socket_connect($socket, $vbhost, $port)){
  print "Connection to VB host open, continuing ... <br />";
  $message="refresh";
  $len = strlen($message); 
  $sent = socket_write($socket, substr($message, $offset), $len);
  if ($sent === false) {
    print "Failed to write to socket<br />";
  } else {
    print "Send message on socket<br />";
  }
} else {
  print "Failed to connect to VB app ...<br />";
}
socket_close($socket);

Open in new window

0

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
SwafnilCommented:
Missed to initialize $offset (which doesn't make sense in the given scenario, I copied it from an old socket project were data was send repeatedly on the same socket. See new code below.
<?php
$vbhost = "localhost";
$port = 80; // or whatever port is listened on
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (socket_connect($socket, $vbhost, $port)){
  print "Connection to VB host open, continuing ... <br />";
  $message="refresh";
  $len = strlen($message); 
  $sent = socket_write($socket, $message, $len);
  if ($sent === false) {
    print "Failed to write to socket<br />";
  } else {
    print "Send message on socket<br />";
  }
} else {
  print "Failed to connect to VB app ...<br />";
}
socket_close($socket);

Open in new window

0
exxos_ukAuthor Commented:
Connection to VB host open, continuing ...
Send message on socket

is what I get, I changed the IP and port to match my VB code. Though the VB app does not see anything. the VB side I listed below , ive changed it so many times, but should be correct..
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

exxos_ukAuthor Commented:

Private Sub Form_Load()
sckServer.Protocol = sckUDPPProtocol
sckServer.LocalPort = 1122
sckServer.RemotePort = 1122
Call sckServer.Bind


      
   sckClient.Protocol = sckUDPProtocol
   sckClient.RemoteHost = "212.69.47.157" ' Text3.Text
   sckClient.RemotePort = 8080



End Sub


Private Sub sckServer_DataArrival(ByVal bytesTotal As Long)
    Dim sData As String
    Call sckServer.GetData(sData)
  Text2.Text = sData
End Sub

Open in new window

0
nffvrxqgrcfqvvcCommented:
Have you tried?
Server:

  Winsock1.Protocol = sckUDPProtocol
  Winsock1.RemotePort = 6113
  Winsock1.RemoteHost = "255.255.255.255"
  Winsock1.Bind 6112
 
Client/ PHP:
$vbhost = " 255.255.255.255";
$port =6112;
0
exxos_ukAuthor Commented:
wwas 6113 a typo ?

in anycase, i keep swapping stuff around, I actually have..

$vbhost = "212.69.47.157";
$port = 1122; // or whatever port is listened on

where the vbhost is my own PC IP.

sckServer.Protocol = sckUDPPProtocol
sckServer.LocalPort = 1122
'sckServer.RemotePort = 1122
'sckServer.RemoteHostIP = "83.170.75.243"
sckServer.RemoteHost = "83.170.75.243"
Call sckServer.Bind

83.170.75.243 is the site IP, though I keep swapping options around and nothing seems to work. I am trying a packet sniffer and the port number does not look right. I see the packet, but seems to come down on port 4891  (though does change a few numbers), so maybe the PHP script is not sending on the right port or not being set for some reason ?!




0
exxos_ukAuthor Commented:
my router log says  

Firewall: packet accept. 83.170.75.243(52602) --> 212.69.47.157(1122), Protocol UDP.
 Sunday, Apr 11,2010 17:14:12

so it does actually look right there. my VB app *should* be working :-(
0
nffvrxqgrcfqvvcCommented:
I have to ask but can you confirm your VB application isn't blocked by a firewall application when attempting to open the bind port? Windows firewall will block an application from opening a port until the user chooses (Unblock). But other firewall applications might block everything unless you set a filter for the application.
0
exxos_ukAuthor Commented:
i turned off the firewall about a hour ago. I jut tried unplugged my router and using a normal modem just in case, still does not work :(
0
exxos_ukAuthor Commented:
ok I worked it out!!!  just sat here thinking how my typos sux and then read my code again

sckServer.Protocol = sckUDPPProtocol

just got the REFRESH command back from the PHP script from Swafnil! so that solved all the PHP stuff!

0
exxos_ukAuthor Commented:
solved the PHP problem! the VB part was my own typos! Though the PHP script helped a great deal too! thanks!
0
SwafnilCommented:
Glad to here you got it working! Btw, your application and the scenario really sound interesting, would be worth a blog post on a geek site like this one ;-)
0
exxos_ukAuthor Commented:
"idiots with typos" I guess would be a good title! saying that, when I was not getting anywhere with UDP, I changed to TCP, then I changed back to UDP, so I guess that was when the typo happend.  The app is just a experiment I am running, some of my apps just poll the server every few seconds, but with a routine like this the server can just issue a "refresh" command, actually your PHP code already have "refresh" in there, so worked out kinda good ;)  Now the VB app does not have to keep polling the server, well thats the idea anyway.
0
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.