View Full Version : Live For Speed and Delphi??
Deviance1992
6th October 2007, 11:42
hy!
i proggraming in delphi
i recrived in delphi this messege in udp : ěě█◘╚ , and how to decode this? or where help me? (sry for my bad english :shrug: )
Bob Smith
6th October 2007, 12:45
a) That's probably not supposed to be interpreted as ASCII
b) If you don't tell us where you're getting that message from, we can't help. I'm assuming it's from an Insim packet?
AndroidXP
6th October 2007, 13:32
No idea about Delphi, but assuming you're talking about InSim, have a look at LFS/docs/InSim.txt - this contains vital information about how InSim works and the structure definitions of the InSim packets.
Deviance1992
6th October 2007, 13:44
i recrived only 4 char, and i use indy component and memo!
w8 and i upload my program
Deviance1992
6th October 2007, 18:45
see:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer,
ExtCtrls;
type
TForm1 = class(TForm)
udp: TIdUDPServer;
Label1: TLabel;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ip: string;
port: integer;
rpm:integer;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var g:string;
begin
label1.Caption:=udp.ReceiveString(ip, port);
//udp.ReceiveBuffer(ip,port,rpm);
//str(rpm,g);
//label1.Caption:=g;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ip := '127.0.0.1';
port := 12000 ;
end;
end.
how to get the udp packets?
mikey_G
6th October 2007, 19:33
This is the first time I've seen pascal, so i dont really know whats wrong or right, but im looking funny at this line:
label1.Caption:=udp.ReceiveString(ip, port);
What I think you're doing here is setting a label control to the data of the whole udp packet, and you're saying to treat the data as a string (which I think is wrong). I also haven't seen anywhere that you read the udp data in a buffer or structure so you can actually extract the data from the packet.
I could be all wrong in this, but who knows :)
Deviance1992
6th October 2007, 19:51
This is the first time I've seen pascal, so i dont really know whats wrong or right, but im looking funny at this line:
label1.Caption:=udp.ReceiveString(ip, port);
What I think you're doing here is setting a label control to the data of the whole udp packet, and you're saying to treat the data as a string (which I think is wrong). I also haven't seen anywhere that you read the udp data in a buffer or structure so you can actually extract the data from the packet.
I could be all wrong in this, but who knows :)
no example? :( i from hungary, and here delphi is a best :)
label1.Caption:=udp.ReceiveString(ip, port); this is no wrong ;) i see this in label: ~#S.. and more :(
AndroidXP
6th October 2007, 20:25
Yes it is wrong. LFS doesn't send strings, it sends data packets (binary data!) in the format specified in InSim.txt. Of course you can read that stuff into strings, but it doesn't make any sense whatsoever. You'd then have to convert these strings to their byte representation and "cast" them into the packet structures.
the_angry_angel
6th October 2007, 20:35
The data from LFS is not a string. It's a stream of bytes which is different with each packet. You need to read the data you get from your receive functions and then separate each packet into it's relevant data types. What this means is that you can read it into a string, but then you need to parse it further to make it usable.
Please note, that I am not familiar with Delphi at all, and I've only found this out via googling for a few minutes.
The easiest way to do this in Delphi would appear to be to create a record, which is like a structure in C (this is how the packets are sent), and then copy the stream into a temporary instance of this record. Voila you should beable to read it in.
Each packet is started with it's size and then followed by the type of packet.
For example:
IS_VER is a 20 byte packet with the following format;
1 unsigned char defining the size (in this case the value is 20)
1 unsigned char defining the type (in this case the value is ISP_VER which is 2)
1 unsigned char defining a request id, should you have set one
1 unsigned char set to 0
8 char array defining the version of LFS
6 char aray defining whether it's DEMO, S1 or S2
1 unsigned short (2 byte integer) containing the version number of InSim
I'm guessing in Delphi it would be something like this:IS_VER = Record
size : Byte;
type : Byte;
reqi : Byte;
zero : Byte;
version : String[8];
product : String[6];
insimver : Word;
end;
Edit: Damn you Android! You win this time!
mikey_G
6th October 2007, 20:43
no example? :( i from hungary, and here delphi is a best :)
label1.Caption:=udp.ReceiveString(ip, port); this is no wrong ;) i see this in label: ~#S.. and more :(
Like I said, I've never seen delphi code until tonight.
I found some thing on google, but to be honest delphi is quite a "almost dead" language, so there aren't a lot of tutorials about this subject.
http://www.prog.hu/tudastar/71058/Delphi+UDPserver-valamit+elhibaztam.html?pop=0
Radekteam
25th February 2008, 18:17
I know that this post is old by try my source code. It's in Delphi 7 and it's works
http://www.lfsforum.net/showthread.php?p=721349 (http://www.lfsforum.net/showthread.php?p=721349)
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.