View Full Version : Simple VB6 example needed
Rooble
10th March 2006, 06:56
Morning all :Looking_a
Ok so, ive decided i want to get back into good ol' VB6, and i hope no one attempts to convince otherwise. I really havent played with it for a long time, and i was wondering if someone could post a very simple example as short and clean and commented as possible to enable me to connect to this InSim business and perhaps relay messages? Ill try build from there as best i can, or give up.
Thanks in advanced! :smileypul
Bob Smith
10th March 2006, 15:40
Look for Stuff's (RayOK's) basic insim program for pointers. Not exactly commented or written for beginners but could prove very handy.
Nuthin wrong with VB6 though, it serves it's purpose for GRC well enough. I could post code excerpts from that but then you said simple and I don't want to make your head explode. :)
Dygear
10th March 2006, 16:52
Post it, I am sure that some one will translate / comment the code.
Rooble
11th March 2006, 05:39
Yeh ive downloaded the ImSim app that RayOk coded, but its looks overly complex for what seems to me a simple task, all im needing is the connection process and the sending of text, and if i could have that in less then 500 lines :thumb: that'd be dandy, if not, ill just slug my way through his code picking out what i need.
Thanks for the replies lads!
Stuff
11th March 2006, 08:05
Little ol' me? :shy: Thanks for the consideration but it all depends on what you want to do. The okSocket I put together is basic for simple UDP packets that InSim uses but there are definitely other ways to accomplish a task. As a matter of fact, I'm working on a better version of my okSocket that will make it more robust for use with TCP sockets too. (HTTP stuff!) Or, you can do what I did and start researching winsock...
http://www.winsockvb.com is a good place to start. They describe the basics and go into depth on both the Winsock control and the API that I use. http://www.killervb.com also has tons of excellent, somewhat complex, code that will give you a good base for an InSim app too. Even more winsock info can be found here http://www.programmersheaven.com/zone15/articles/article324.htm And! Another place to get some great code is from the mixed site, Planet Source Code (http://www.pscode.com/). Charles P.V. makes some great, easy-to-use, pure API, controls such as status bars, toolbars, listviews, trees, etc. I took from his code and even he took from Paul Canton with the self-sublcassing control/class/form.
Yes, tons to soak up for what seems to be a simple concept but once you get into it, it gets complicated fast and turns into an art to get it working just right all the time, for everyone. :) Overall, no matter what ya do, we will be able to help ya out. :D
filur
11th March 2006, 18:35
..and if i could have that in less then 500 lines :thumb: that'd be dandy
How about 10 lines of php? :razz:
Dygear
11th March 2006, 18:47
Don't tease, post it.
filur
11th March 2006, 19:06
stream_set_blocking($socketOut = fsockopen("udp://127.0.0.1", 29999), FALSE);
stream_set_blocking($socketIn = stream_socket_server("udp://127.0.0.1:30000", $errno, $errstr, STREAM_SERVER_BIND), FALSE);
fwrite($socketOut, "ISI\0" . pack("Scc", 30000, 1+8+16+32, 1) . str_pad("adminpw", 16, "\0"));
$time = microtime(TRUE);
while(microtime(TRUE) - $time < 30) {
if ($packet = fread($socketIn, 1024)) {
$time = microtime(TRUE);
echo "<Keanu Reeves> wooah.. " . substr($packet, 0, 3) . "\n";
} usleep(100 * 1000);
}
10 lines! :)
Edit: stream_socket stuff is php5 (cvs?) only. I think.
Dygear
11th March 2006, 22:45
Nice work, filur. Hey anyone here happen to have the InSim Manual.
[EDIT] While I am at it, how would I go about unpacking a string I get from InSim. Like I am getting back information from the server (when I run the script) but its allways MCI then some gobbledygoop.
[EDIT2] Ok I think I am starting to understand how this is going to work. I looked at the pack string function for PHP and I saw that Scc refers to "unsigned short (always 16 bit, machine byte order)" for the S and "signed char" for the c. So for each of the types of information from the server I will have to make up a case statment to catch all of the types from the server... Now I really do need that InSim Manual.
[EDIT3] Found it in the docs part of the LFS dir. Thanks anyway ... :)
Guber-X
30th May 2006, 22:59
i get a time out error :(
<Keanu Reeves> wooah.. ACK
Fatal error: Maximum execution time of 30 seconds exceeded in c:\Inetpub\wwwroot\server.php on line 11
filur
30th May 2006, 23:11
i get a time out error :(
set_time_limit() (http://php.net/manual/en/function.set-time-limit.php)
If seconds is set to zero, no time limit is imposed.
Don't run a neverending script under a webserver. :)
Dygear
30th May 2006, 23:34
Yea, not alot of people know that PHP files are not just for web servers. PHP is a fully capable application programing langue. Yea, the name might mean Hypertext Preprocessor, but that does not mean that is it's only application.
You can also run PHP progams from the console. Just make sure that your php.exe is in the path variable for windows ( I don't know what you have to do for linux ) or that you run it like so "php ../path/to/script/main.php" then it will run in the command window.
the_angry_angel
30th May 2006, 23:35
Don't run a neverending script under a webserver. :)
Even if you set the timeout as 0 it still dies after about 8 hours or so, if memory serves correctly. This maybe a HTTPD issue however. But like filur says, its bad "mmkay?"
Edit:
Thanks dygear you kinda made a precursor statement for my next comment... for reference prefixing #!/path/to/php to a file, and then applying +x attributes on the same file will allow you to just run the script as if it were a normal command (on unix derivatives).
Back on topic; perhaps a little brain power is required here as running most kind of socket operations within a webserving page is a bit of a no-no. You may wish to consider creating a queuing system, dumping the requests in and then running a shell / batch script (which could be PHP, or otherwise) to process them every X minutes. It wouldn't be immediate, but it would be a lot nicer and would avoid a few problems. It is more work, however.
Dygear
30th May 2006, 23:40
Even if you set the timeout as 0 it still dies after about 8 hours or so, if memory serves correctly. This maybe a HTTPD issue however. But like filur says, its bad "mmkay?"
*Giggles* You really remind me of one of my old server admins, awsome guy, and an awsome programmer.
the_angry_angel
30th May 2006, 23:44
*Giggles* You really remind me of one of my old server admins, awsome guy, and an awsome programmer.
I try my best :)
Guber-X
31st May 2006, 07:41
okay... so how do i run the script.. haha, dont think ive ever used PHP for application wise...
filur
31st May 2006, 15:45
okay... so how do i run the script.. haha, dont think ive ever used PHP for application wise...
c:\windows\php>php -f myfile.php
gruber@linux:~/php$ php -f myfile.php
PHP: Using PHP from the command line. (http://php.net/features.commandline)
Guber-X
2nd June 2006, 05:19
:(
<b>Fatal error</b>: Call to undefined function: stream_socket_server() in <b>C
:\PHP\server.php</b> on line <b>3</b><br />
filur
2nd June 2006, 09:03
stream_socket stuff is PHP 5, which i think i've already mentioned.
stream_socket_server() (http://php.net/manual/en/function.stream-socket-server.php)
stream_socket_server
(PHP 5)
stream_socket_server -- Create an Internet or Unix domain server socket
the_angry_angel
2nd June 2006, 10:34
Either that or the socket_* functions arent compiled into your build of PHP.
On windows you need to enable the socket extension dll (see your php.ini). On *ix it normally means a recompile.
You can check by putting the following in a page, and viewing the output; <?php phpinfo(); ?>If the socket's are listed in there, then you've got an older version. If its not, then its either not enabled (see above), or not compiled in.
If you're running on rented hosting space, its unlikely they'll turn on sockets, because of security and bandwidth issues.
filur
2nd June 2006, 12:34
Only some of the (older) socket functions are in the extension, the newer stream_ functions are built in (compile opt on linux?) as of PHP 5.
Stone Temple Pilots
17th July 2006, 17:18
Hello Everyone,
Im developing a php script that access LFS through Insim, and i m in trouble, when i try to send ACK packages(keep alive), seems that some mistake in the synthax, because i can send with success, other packages like MST (message send) and SST ( To enabe response about player status, in this case PLP Player in Pitstop).
...
if($socketOut)
{
fwrite($socketOut, "ACK\0" . "0" );
}
else
{
echo "<p> Package dont sent </P>";
}
...
Could some expert in PHP can help me ? because im not :nod:
Regards!
filur
17th July 2006, 18:09
when i try to send ACK packages(keep alive), seems that some mistake in the synthax
ACK is an InSimPack, so the value (0) needs to be a 4-byte signed integer.
fwrite($socketOut, "ACK\0" . pack("i", 0));
vBulletin® v3.7.1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.