The online racing simulator
Simple VB6 example needed
(22 posts, started )
Simple VB6 example needed
Morning all

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!
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.
Post it, I am sure that some one will translate / comment the code.
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 that'd be dandy, if not, ill just slug my way through his code picking out what i need.

Thanks for the replies lads!
#5 - Stuff
Little ol' me? 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.c ... 5/articles/article324.htm And! Another place to get some great code is from the mixed site, Planet Source Code. 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.
#6 - filur
Quote from Rooble :..and if i could have that in less then 500 lines that'd be dandy

How about 10 lines of php?
Don't tease, post it.
#8 - filur

<?php 
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$errstrSTREAM_SERVER_BIND), FALSE);
fwrite($socketOut"ISI\0" pack("Scc"300001+8+16+321) . str_pad("adminpw"16"\0"));
$time microtime(TRUE);
while(
microtime(TRUE) - $time 30) {
  if (
$packet fread($socketIn1024)) {
    
$time microtime(TRUE);
    echo 
"<Keanu Reeves> wooah.. " substr($packet03) . "\n";
  } 
usleep(100 1000);
}
?>

10 lines!

Edit: stream_socket stuff is php5 (cvs?) only. I think.
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 ...
i get a time out error

<Keanu Reeves> wooah.. ACK
[B]Fatal error[/B]: Maximum execution time of 30 seconds exceeded in [B]c:\Inetpub\wwwroot\server.php[/B] on line [B]11[/B]

Quote from Guber-X :i get a time out error

set_time_limit()
Quote :If seconds is set to zero, no time limit is imposed.

Don't run a neverending script under a webserver.
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.
Quote from filur :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.
Quote from the_angry_angel :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.
Quote from Dygear :*Giggles* You really remind me of one of my old server admins, awsome guy, and an awsome programmer.

I try my best
okay... so how do i run the script.. haha, dont think ive ever used PHP for application wise...
Quote from Guber-X :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.


<b>Fatal error</b>: Call to undefined function: stream_socket_server() in <b>C
:\PHP\server.php</b> on line <b>3</b><br />

stream_socket stuff is PHP 5, which i think i've already mentioned.

stream_socket_server()

Quote from php.net :stream_socket_server

(PHP 5)
stream_socket_server -- Create an Internet or Unix domain server socket

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.
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.
Quote from Stone Temple Pilots :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.

<?php 
fwrite
($socketOut"ACK\0" pack("i"0));
?>


Simple VB6 example needed
(22 posts, started )
FGED GREDG RDFGDR GSFDG