🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Query servers for info - VB

Started by
14 comments, last by Epzilon 22 years, 9 months ago
define the string in VB
szBlah as String*255
szBlah = ""

The null terminated string was probably much easier to program with in C than any other representations - it''s the way the x86 likes strings to be in RAM if I remember right.

This scenario is an excellent example of why you need to at least learn some C, even to do VB programming.

Can you use message-pump based async sockets?



Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
I find that when working with other applications or manipulating memory, it is easiest to use Byte arrays. Bytes are slower than Integers and Longs (fastest) because the processor is 32 bit, but for things like this it makes it really simple... it is unsigned, so you don't have to think about things like 2s complement. And being a byte, it is easy to convert stuff in your head.

Sub CreateMessage(StoreIn() As Byte, Command As String) Dim i As Long ' 'Make room for message Redim StoreIn(4 + Len(Command)) ' 'Put in long int -1 header For i = 0 To 3  StoreIn(i) = 255 Next ' 'Put in Command For i = 1 To Len(Command)  StoreIn(i + 3) = Asc(Mid$(Command, i, 1)) Next ' 'Null byte StoreIn(4 + Len(Command)) = 0End Sub 


If this is supposed to be really fast code, then I would create a temporary veriable for the length of the string, and also hardcode the first loop, but thats irrelevant.

VB strings in memory firstly have a few bytes (not sure how many, possibly 4) which tell you the length of the string and also a null byte to terminate them at the end. Some operations (such as VarPtr) will pass the beginning of the actual string part, without the length included, which makes life easier in some ways but it hides you from what is really happening (and there could possibly be some problems if the string changes without the length header changing).

Best solution is to either use fixed length strings as Magmai said or use a byte array... pretty much the same thing except you can resize a dyanamic byte array.

EDIT: code tags get rid of blank lines.

Trying is the first step towards failure.

Edited by - ragonastick on September 18, 2001 12:59:39 AM
Trying is the first step towards failure.
Try this:

Winsock.SendData "something" & vbCRLF

Also, on planetsourcecode.com, VB section, there is an Unreal Torunament query-server program, maybe also one for Halflife, might be worth looking into. (Since both games use winsock, so both have probably the same method of sending/receiving things)

quote:
It''s rare you can mention VB without people trying to convince you to start with c++


Someone already did. And I think it''s a bad thing people say that sort of stuff.

Almar



www.persistentrealities.com for Inline ASM for VB, VB Fibre, and other nice code samples in C++, PHP, ASP, etc.<br/>Play Yet Another Laser Game!<br/>
quote:
Winsock.SendData "something" & vbCRLF


I don't see how that would work, unless you made the first 4 characters of "something" Chr$(255)... and the vbCRLF (equivalent of "\n" in C) wouldn't do much either. vbNullChar might be better.

Edited by - ragonastick on September 19, 2001 5:13:20 AM
Trying is the first step towards failure.
ragonastick, thank you so much. Your example worked.
And thanks to the rest of you.
quote: Original post by Magmai Kai Holmlor

Can you use message-pump based async sockets?


...(hurts his brain for a sec)...yyeahh, you can, but I don''t know how effective it is.

------------
-WarMage
...tig ol'' bitties for me, baby...

This topic is closed to new replies.

Advertisement