The online racing simulator
Help noob
(24 posts, started )
Help noob
I new to programming, can some one help i cant connect with LFS i use VB.Net
thank you for reading

regards Andy
#2 - filur
is there a simple code to connect to lfs? when i download the code, net try to update form vb6 to .Net them but the programe stop working.

Filur thank you for the links
#4 - Stuff
Yeah.. dunno how that would behave with .net. Not at all familiar with VB.net but I would probably scrap the API socket stuff in my later examples and go with some kind of .net winsock control..to start off at least. That is, if it has one

Most things I've heard about VB6 -> .net involves a major rewrite if not just starting over. So, I can't help ya much but post what you have anyway and we can see if we can get it to connect.

[EDIT] Oh! Wait! Messiah is making a project called LFS Live! That is .net 1.1 and will definitely help ya. Check it out: http://lfslive.sourceforge.net/ How could I forget that.. :doh:
Thank you for that i will give is a good look Tomorrow but it look good
I had a good look at it but it all in C#, I whose hoping that I could us Visual Basic if not I will have to lean C#

I do a Winsock is the byte and arrays I have to send that make my go crazy
With VB, you need to fill the byte and array fields byte-by-byte, because VB uses BSTR's, instead of CSTR's (i.e. char arrays). I believe this still applies for the equivilent .NET languages.
this is wwhat i got
Dim Bytes(4) As Char
Dim NodeSecs(1) As Byte

the main code i think it no where near what it ment to by

Bytes(0) = "I"
Bytes(1) = "S"
Bytes(2) = "I"
Bytes(3) = ChrW(0)
NodeSecs(0) = 0
NodeSecs(1) = 0
Winsock1.Connect("127.0.1", 29999)
Winsock1.Send(Bytes)
Winsock1.RemotePort = (29998)

how bad is it
Its bad.........
your packet is not ready to send! you forgot some important thinks:

an "ISI" Packet includes the apps remote port, admin pass, flags ,nodesecs:

It´s a c++ example but coding is coding........

[COLOR=#000000][COLOR=#ff8000]//a small c++ example:

char v = 0;
InSimInit init_pack;
memset(&init_pack, 0, sizeof(InSimInit));
strcpy(init_pack.Id, "ISI" + v);
init_pack.Port = 12345;
init_pack.Flags = ISF_RACE_TRACKING|ISF_KEEP_ALIVE;
init_pack.NodeSecs = 0;
strcpy(init_pack.Admin,Text.c_str());
UDP1->SendBuffer((char*)&init_pack,1024,sizeof(InSimInit))[/COLOR][/COLOR]

Ohh, a local host address is a 127.0.0.1/255.0.0.0
dose this look better

Dim ISI(4) As Char
Dim admin(16) As Char
Dim port As String
Dim flags As Byte
Dim isiports(6) As Byte
Dim NodeSecs As Byte

Public Sub InSimInit()
ISI(0) = "I"
ISI(1) = "S"
ISI(2) = "I"
ISI(3) = ChrW(0)
NodeSecs = 0
flags = (16)
port = 12345
admin(0) = "T"
admin(1) = "E"
admin(2) = "S"
admin(3) = "T"
End Sub

Yes
How would I send the data to lfs?

and thank your for your help JogDive
Quote from Andy1080 :How would I send the data to lfs?

and thank your for your help JogDive

through an udp socket ?
i now have this

Dim ISI(4) As Char
Dim admin(16) As Char
Dim port As String
Dim flags As Byte
Dim NodeSecs(2) As Byte
Dim ip As IPEndPoint
Dim sock As New UdpClient
Dim insim(13) As Byte

Public Sub InSimInit()

BitConverter.GetBytes(ISI(0) = "I").CopyTo(insim, 0)
BitConverter.GetBytes(ISI(1) = "S").CopyTo(insim, 1)
BitConverter.GetBytes(ISI(2) = "I").CopyTo(insim, 2)
BitConverter.GetBytes(ISI(3) = ChrW(0)).CopyTo(insim, 3)
BitConverter.GetBytes(NodeSecs(0) = 0).CopyTo(insim, 4)
BitConverter.GetBytes(flags = (16)).CopyTo(insim, 5)
BitConverter.GetBytes(port = 29999).CopyTo(insim, 6)
BitConverter.GetBytes(admin(0) = "T").CopyTo(insim, 7)
BitConverter.GetBytes(admin(1) = "E").CopyTo(insim, 8)
BitConverter.GetBytes(admin(2) = "S").CopyTo(insim, 9)
BitConverter.GetBytes(admin(3) = "T").CopyTo(insim, 10)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
InSimInit()
sock.Send(insim, 13)
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
sock.Connect("127.0.0.1", 29999)
End Sub

Andy,

If you just want to communicate with LFS from VB.NET and not worry about implementing the InSim protocol, take a look at this. It's in C#, but if you just reference the dll, you can use it directly in VB without having to worry about C#.

HTH,
ether
I had a break form all of this programming now I am back I have look at my code and edit a bit but I just cant get it connect using the Udp port, this is my code
Dim udp As New UdpClient
Dim ISI(4) As Char
Dim admin(16) As Char
Dim port As String
Dim flags As Byte
Dim NodeSecs As Byte
Dim ip As IPEndPoint
Dim Insim(13) As Byte

Public Sub InSimInit()
BitConverter.GetBytes(ISI(0) = "I").CopyTo(Insim, 0)
BitConverter.GetBytes(ISI(1) = "S").CopyTo(Insim, 1)
BitConverter.GetBytes(ISI(2) = "I").CopyTo(Insim, 2)
BitConverter.GetBytes(ISI(3) = ChrW(0)).CopyTo(Insim, 3)
BitConverter.GetBytes(port = 30001).CopyTo(Insim, 6)
BitConverter.GetBytes(flags = (16)).CopyTo(Insim, 5)
BitConverter.GetBytes(NodeSecs = 0).CopyTo(Insim, 4)
BitConverter.GetBytes(admin(0) = "T").CopyTo(Insim, 7)
BitConverter.GetBytes(admin(1) = "E").CopyTo(Insim, 8)
BitConverter.GetBytes(admin(2) = "S").CopyTo(Insim, 9)
BitConverter.GetBytes(admin(3) = "T").CopyTo(Insim, 10)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

InSimInit()
udp.Connect("127.0.0.1", 30001)
For i As Integer = 0 To 10
udp.Send(Insim, i)
'Stop
Next i

End Sub

I thing I am close to getting working. The “chrw” line doesn’t seem right chrw(0) converts a integer to a Ascll code or is that right?
I'm no expert with VBasic these days, but a few things don't look right.
these sections for example:
BitConverter.GetBytes(ISI(0) = "I").CopyTo(Insim, 0)

It seems a little unnecessary to do it like that. I could be totally wrong, but it just doesn't look right. Try:

UdpClient.ISI(0) = CByte("I")
... etc
UdpClient.ISI(3) = CByte(vbNULL)

Out of interest, do you get any errors from winsock at all?

TBH, I'd have a look at RayOK's AutoSkin utility's source at http://rayok.lfsnal.org/LFS/?page=autoskin, in particular have a looksie at InSim.bas.
I don't use Winsock I use UdpClient, and the code that you give my doesn’t seem to work.
when I use my code Lfs said Insim: packet received before ISI packet
That make my think that doesn’t received it in the right order. When I look at the autoskin code
vb.net converted it and made it a right mass. The
[LEFT]BitConverter.GetBytes(ISI(0) = "I").CopyTo(Insim, 0)[/LEFT]


is the only why that i can think of geting to send using the udpclient.
As I'd said in the past, I'm not upto speed on .NET things at the moment, and for this reason Id highly recommend going down sdether's suggested route, of using this.
Is it not ..
Quote :Dim port As String

Quote :struct InSimInit
{
..
word Port;

.. where ..
Quote :word 2-byte unsigned integer

I've never used visual basic, but a string value of "30001" doesn't look like a 2-byte value to me.
I think I am going to admit defeat, I am new to programming so
I think I should learn more before coming back to this.
Thank you all for your help
No! Don't give up yet.. Maybe I can help to get you back on track

I'm pretty sure that LFS checks the size of the packet you are sending it to tell if it has all the data, so you have to make sure when you do .send, that the array/packet is the right size and the right order. The size of the InSim packet (below) is 24 bytes. From your code (Dim InSim(13) As Byte), you are only sending 14 bytes. See? 14 != 24 so LFS rejects your data.

What you have to do is make InSim(23) As Byte and make sure the data goes into the right spot. Can't just stick the data anywhere and expect the program to determine where something starts/ends

For example..
ISI + chr(0) goes into 0-3 '<-- one byte for each character so make sure it's not unicode
2 port bytes goes into 4-5 '<-- 2 bytes for 0-65535 so make sure the number is not signed
flag byte goes into 6
nodesecs goes into 7
password goes into 8-23


struct InSimInit // UDP packet to initialise the InSim system
{
char Id [4]; // ISI + zero
word Port; // Port for UDP replies from LFS (0...65535)
byte Flags; // Bit flags for options - see below
byte NodeSecs; // Number of seconds between NLP or MCI packets (0=none)
char Admin [16]; // Admin password (required if set in LFS host options)
};

See how that goes and keep trying.
Stuff ok i will not give up just yet, i made a little change
Dim Insim(23) As Byte
BitConverter.GetBytes(ISI(3) = vbNullChar).CopyTo(Insim, 3)
Dim port As UInt16

i think that it is sending ISI + 0 but i not 100% ,And I don’t know how to use the uint16 as uint16 = 30001 doesn’t work?

thank you stuff
I dunno what a uint16 is but I'm guessing it stands for an unsigned integer thats 16 bits? That's what you need, just not sure how to copy it over to that InSim array. Since you're copying the individual bytes, you have to figure out how to separate that uint16 into 2 bytes. Not sure if I can help right away but have a look at other code, esp LFS.Live by Messiah. Maybe someone with .NET exp will step in. I'm not too familiar with .NET, mostly VB6 and Java

Remember with the ISI packet, that port is the one you are listening on for LFS data, not the one you are sending to. Keep them separate otherwise LFS will start to receive its own data and get really b0rky

Probably the best way is to create a user-defined type (in VB6 anyway), aka a struct in C. If you do that, everything is in place as it should be. Only thing you have to do is fill it in then copy the type into an array to send.

Keep playing

Help noob
(24 posts, started )
FGED GREDG RDFGDR GSFDG