BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Please help Indy 10 Delphi 2005
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Dev
Guest





PostPosted: Wed Jan 12, 2005 9:32 pm    Post subject: Please help Indy 10 Delphi 2005 Reply with quote



As stated I'm using Indy 10 and Delphi 2005...

I'm sending a string of raw hex characters to a game server and in return
should get a string of hex characters, which I do not want to capture as a
string like I would be doing if I used 'IdUdpClient.ReceiveString()' so I'm
trying to use .ReceiveBuffer(buf,SizeOf(buf)) here's my code:

procedure TForm1.Button1Click(Sender: TObject);
var
buf:array[0..255] of char;
dataLen:integer;
begin

SendStr := #254#253#0#224#235#45#14#20#1#11#1#5#8#10#51#52#53 +
#19#4#54#55#56#57#20#58#59#60#61#0#0; // the hex string

UDP1.Send(SendStr);

UDP1.ReceiveBuffer(buf,SizeOf(buf));

if buf <> 0 then
Memo1.Lines.Add('No response from server.')
else
Memo1.Lines.Add('Received: ' + buf[0]); // I know this part won't
display the whole string!

end;

Am I using ReceiveBuffer properly? Because this would usually compile with
Indy 9 & Delphi 7 but not with Indy 10 and Delphi 2005. I'm getting the
error:

"[Error] status.pas(49): E2250 There is no overloaded version of
'ReceiveBuffer' that can be called with these arguments"

Can someone please post a pseudo code or delphi code solution to this
problem please.


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Jan 12, 2005 10:22 pm    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote




"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote


Quote:
I'm sending a string of raw hex characters to a game server

Why are you sending the data as a string? The values you are using are not
even in the valid range for string characters.

Quote:
and in return should get a string of hex characters, which I do not
want to capture as a string

Then why are you treating the data as strings in the first place? What is
the data supposed to be exactly?

Quote:
UDP1.ReceiveBuffer(buf,SizeOf(buf));

ReceiveBuffer() expects a TIdBytes, not an array of characters. Not only
that, but ReceiveBuffer() does not have a size parameter at all, but you are
passing in a size anyway. It will be interpreted as a timeout instead.

Quote:
if buf <> 0 then

That is not a valid check. Use the actual return value from ReceiveBuffer()
instead.

if UDP1.ReceiveBuffer(buf,SizeOf(buf)) < 1 then begin
Memo1.Lines.Add('No response from server.')
else
...

Quote:
Memo1.Lines.Add('Received: ' + buf[0]); // I know this part won't
display the whole string!


It is not supposed to. You are displaying a single character, not the
entire buffer.

Quote:
Am I using ReceiveBuffer properly?

No. Try this code:

procedure TForm1.Button1Click(Sender: TObject);
var
buf: TIdBytes;
begin
SetLength(buf, 30);

buf[0] = #254;
buf[1] = #253;
buf[2] = #0
buf[3] = #224
buf[4] = #235;
buf[5] = #45;
buf[6] = #14;
buf[7] = #20
buf[8] = #1;
buf[9] = #11;
buf[10] = #1;
buf[11] = #5;
buf[12] = #8;
buf[13] = #10;
buf[14] = #51;
buf[15] = #52;
buf[16] = #53;
buf[17] = #19;
buf[18] = #4;
buf[19] = #54;
buf[20] = #55;
buf[21] = #56;
buf[22] = #57;
buf[23] = #20;
buf[24] = #58;
buf[25] = #59;
buf[26] = #60;
buf[27] = #61;
buf[28] = #0;
buf[29] = #0;

UDP1.Send(buf);
SetLength(buf, 256);

if UDP1.ReceiveBuffer(buf) < 1 then
Memo1.Lines.Add('No response from server.')
else
Memo1.Lines.Add('Received: ' + BytesToString(buf));
end;

Quote:
Because this would usually compile with Indy 9 & Delphi 7
but not with Indy 10 and Delphi 2005. I'm getting the error:

As well you should be. The interface changed in Indy 10. Your code has not
taken that into account.

Quote:
"[Error] status.pas(49): E2250 There is no overloaded version
of 'ReceiveBuffer' that can be called with these arguments"

Exactly. You are passing the wrong parameters to ReceiveBuffer().


Gambit



Back to top
Dev
Guest





PostPosted: Thu Jan 13, 2005 12:01 am    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote



Please advise me again Remy...

What I am trying to do is in effect convert this php code:

<?php
$ipaddr = "217.44.119.250";
$port = "5121";
$timeout = 20;
$connect = fsockopen( "udp://" . $ipaddr, $port, $errno, $errstr,
$timeout );
if ( ! $connect ) {
print( " n" );
print( "<h3>ERROR: $errno - $errstr</h3>
n" );
exit;
} else {
socket_set_timeout( $connect, $timeout );
$send =
"xFExFDx00xE0xEBx2Dx0Ex14x01x0Bx01x05x08x0Ax33x34x35x13x04x36x37x38x39x14x3Ax3Bx3Cx3Dx00x00";
fwrite( $connect, $send );
$output = fread( $connect, 5000 );
if ( ! $output ) {
print ( "<h1>Server is down.
</h1>n" );
} else {
$lines = explode( "x00", $output );
print( "Server IP: <i class='r'>$ipaddr</i>:<i
class='r'>$port</i>
n" );
print( "Server Status: <i class='r'>Online</i>
n" );
print( "Game Category: <i class='r'>" );
if ( $lines[16] == "274" ) {
print( "Action</i>
n" );
} elseif ( $lines[16] == "363" ) {
print( "Story</i>
n" );
} elseif ( $lines[16] == "364" ) {
print( "Story Lite</i>
n" );
} elseif ( $lines[16] == "275" ) {
print( "Role Play</i>
n" );
} elseif ( $lines[16] == "276" ) {
print( "Team</i>
n" );
} elseif ( $lines[16] == "365" ) {
print( "Melee</i>
n" );
} elseif ( $lines[16] == "366" ) {
print( "Arena</i>
n" );
} elseif ( $lines[16] == "277" ) {
print( "Social</i>
n" );
} elseif ( $lines[16] == "279" ) {
print( "Alternative</i>
n" );
} elseif ( $lines[16] == "278" ) {
print( "PW Action</i>
n" );
} elseif ( $lines[16] == "367" ) {
print( "PW Story</i>
n" );
} elseif ( $lines[16] == "368" ) {
print( "Solo</i>
n" );
} elseif ( $lines[16] == "370" ) {
print( "Tech Support</i>
n" );
}
print( "Play Type: <i class='r'>$lines[2]</i>
n" );
print( "Game Name: <i class='r'>$lines[3]</i>
n" );
print( "Module Name: <i class='r'>$lines[4]</i>
n" );
print( "Version Number: <i class='r'>$lines[14]" );
if ( $lines[20] == '1' ) {
print( " / XP-1 " );
} elseif ( $lines[20] == '2' ) {
print( " / XP-2 " );
} elseif ( $lines[20] == '3') {
print( " / XP-1 / XP-2 " );
}
print( "</i>

n" );

print( "Level Range: <i class='r'>$lines[7]</i> - <i
class='r'>$lines[8]</i>
n" );

print( "Player vs. Player: " );
if ( $lines[9] == "NONE" ) {
print( "<i class='r'>" );
} elseif ( $lines[9] == "FULL" ) {
print( "<i class='r'>" );
} else {
print( "<i class='r'>" );
}
print( "$lines[9]</i>
n" );

print( "Character Vault: " );
if ( $lines[19] == '1' ) {
print( "<i class='r'>Local Vault</i>
n" );
} else {
print( "<i class='r'>Server Vault</i>
n" );
}
print( "Only One Party: " );
if ( $lines[12] == '1' ) {
print( "<i class='r'>enabled</i>
n" );
} else {
print( "<i class='r'>disabled</i>
n" );
}

print( "Player Pause: " );
if ( $lines[13] == '1' ) {
print( "<i class='r'>enabled</i>
n" );
} else {
print( "<i class='r'>disabled</i>
n" );
}

print( "Item Level Restrictions: " );
if ( $lines[18] == '1' ) {
print( "<i class='r'>enabled</i>
n" );
} else {
print( "<i class='r'>disabled</i>
n" );
}
print( "Enforce Legal Characters: " );
if ( $lines[17] == '1' ) {
print( "<i class='r'>enabled</i>
n" );
} else {
print( "<i class='r'>disabled</i>
n" );
}

print( "Password: " );
if ( $lines[10] == '0' ) {
print( "<i class='r'>not required</i>
n" );
} else {
print( "<i class='r'>required</i>
n" );
}

print( "Players: <i class='r'>$lines[5]</i> / <i
class='r'>$lines[6]</i>

n" );
$dlines = explode( "n", $lines[15] );
print( "Server Description:
" );
print( "n" );
foreach ( $dlines as $dline ) {
print( "$dline
n" );
}
print( "
n" );
}
}
fclose( $connect );
?>

If you can help me in any way I will be greatly in your debt. At the moment
I'm just trying to get the receiveing of the returned data right, the rest
will be easy. What I get sent through Delphi and what Ethereal sniffs (by
packet sniffing) are two different things though. At the moment I just end
up with '~}' instead of what ethereal gets...

'.....Test Server.openplaying.Test
Server.Prelude.0.6.1.40.PARTY.0.5121.1.1.8066..This module was designed for
one, level 1 character. Version 1.0.1.274.1.1.1.0.'




"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote in message
news:41e59758$1 (AT) newsgroups (DOT) borland.com...

I'm sending a string of raw hex characters to a game server

Why are you sending the data as a string? The values you are using are
not
even in the valid range for string characters.

and in return should get a string of hex characters, which I do not
want to capture as a string

Then why are you treating the data as strings in the first place? What is
the data supposed to be exactly?

UDP1.ReceiveBuffer(buf,SizeOf(buf));

ReceiveBuffer() expects a TIdBytes, not an array of characters. Not only
that, but ReceiveBuffer() does not have a size parameter at all, but you
are
passing in a size anyway. It will be interpreted as a timeout instead.

if buf <> 0 then

That is not a valid check. Use the actual return value from
ReceiveBuffer()
instead.

if UDP1.ReceiveBuffer(buf,SizeOf(buf)) < 1 then begin
Memo1.Lines.Add('No response from server.')
else
...

Memo1.Lines.Add('Received: ' + buf[0]); // I know this part won't
display the whole string!

It is not supposed to. You are displaying a single character, not the
entire buffer.

Am I using ReceiveBuffer properly?

No. Try this code:

procedure TForm1.Button1Click(Sender: TObject);
var
buf: TIdBytes;
begin
SetLength(buf, 30);

buf[0] = #254;
buf[1] = #253;
buf[2] = #0
buf[3] = #224
buf[4] = #235;
buf[5] = #45;
buf[6] = #14;
buf[7] = #20
buf[8] = #1;
buf[9] = #11;
buf[10] = #1;
buf[11] = #5;
buf[12] = #8;
buf[13] = #10;
buf[14] = #51;
buf[15] = #52;
buf[16] = #53;
buf[17] = #19;
buf[18] = #4;
buf[19] = #54;
buf[20] = #55;
buf[21] = #56;
buf[22] = #57;
buf[23] = #20;
buf[24] = #58;
buf[25] = #59;
buf[26] = #60;
buf[27] = #61;
buf[28] = #0;
buf[29] = #0;

UDP1.Send(buf);
SetLength(buf, 256);

if UDP1.ReceiveBuffer(buf) < 1 then
Memo1.Lines.Add('No response from server.')
else
Memo1.Lines.Add('Received: ' + BytesToString(buf));
end;

Because this would usually compile with Indy 9 & Delphi 7
but not with Indy 10 and Delphi 2005. I'm getting the error:

As well you should be. The interface changed in Indy 10. Your code has
not
taken that into account.

"[Error] status.pas(49): E2250 There is no overloaded version
of 'ReceiveBuffer' that can be called with these arguments"

Exactly. You are passing the wrong parameters to ReceiveBuffer().


Gambit





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Jan 13, 2005 12:57 am    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote


"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote


Quote:
What I am trying to do is in effect convert this php code:

You are not reading the socket the same way that the PHP code is reading.
The PHP code reads until there is nothing left to read. Your code, only the
other hand, is making Indy read a specific amount of data, waiting until
that much data is actually available, and then stop reading even if more
data is available. A closer translation would be as follows:

procedure TForm1.Button1Click(Sender: TObject);
var
Buf, RecvBuf: TIdBytes;
Read: Integer;

function Read(var VBytes: TIdBytes; ATimeout: Integer): Boolean;
var
RecvBuf: TIdBytes;
NumRead, TotalRead, Offset: Integer;
begin
TotalRead := 0;
SetLength(RecvBuf, 1024);
while UDP1.Binding.Readable(ATimeout) then begin
NumRead := UDP1.Binding.Receive(RecvBuf);
if NumRead < 1 then Break;
Offset := Length(VBytes);
SetLength(VBytes, Offset + NumRead);
CopyTIdBytes(RecvBuf, 0, VBytes, Offset, NumRead);
Inc(TotalRead, NumRead);
end;
Result := (TotalRead > 0);
end;

begin
SetLength(Buf, 30);

Buf[0] = #254;
Buf[1] = #253;
Buf[2] = #0
Buf[3] = #224
Buf[4] = #235;
Buf[5] = #45;
Buf[6] = #14;
Buf[7] = #20
Buf[8] = #1;
Buf[9] = #11;
Buf[10] = #1;
Buf[11] = #5;
Buf[12] = #8;
Buf[13] = #10;
Buf[14] = #51;
Buf[15] = #52;
Buf[16] = #53;
Buf[17] = #19;
Buf[18] = #4;
Buf[19] = #54;
Buf[20] = #55;
Buf[21] = #56;
Buf[22] = #57;
Buf[23] = #20;
Buf[24] = #58;
Buf[25] = #59;
Buf[26] = #60;
Buf[27] = #61;
Buf[28] = #0;
Buf[29] = #0;

UDP1.Host := '217.44.119.250';
UDP1.Port := 5121;
UDP1.Connect;
try
UDP1.Send(Buf);
SetLength(Buf, 0);
if not Read(Buf, 5000) then
Memo1.Lines.Add('No response from server.')
else
Memo1.Lines.Add('Received: ' + BytesToString(Buf));
finally
UDP1.Disconnect;
end;
end;


Gambit



Back to top
Dev
Guest





PostPosted: Thu Jan 13, 2005 10:26 am    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote

I can't actually get this to compile yet, what Indy compuntents should be
under 'uses'?

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote in message
news:41e5ba6b (AT) newsgroups (DOT) borland.com...

What I am trying to do is in effect convert this php code:

You are not reading the socket the same way that the PHP code is reading.
The PHP code reads until there is nothing left to read. Your code, only
the
other hand, is making Indy read a specific amount of data, waiting until
that much data is actually available, and then stop reading even if more
data is available. A closer translation would be as follows:

procedure TForm1.Button1Click(Sender: TObject);
var
Buf, RecvBuf: TIdBytes;
Read: Integer;

function Read(var VBytes: TIdBytes; ATimeout: Integer): Boolean;
var
RecvBuf: TIdBytes;
NumRead, TotalRead, Offset: Integer;
begin
TotalRead := 0;
SetLength(RecvBuf, 1024);
while UDP1.Binding.Readable(ATimeout) then begin
NumRead := UDP1.Binding.Receive(RecvBuf);
if NumRead < 1 then Break;
Offset := Length(VBytes);
SetLength(VBytes, Offset + NumRead);
CopyTIdBytes(RecvBuf, 0, VBytes, Offset, NumRead);
Inc(TotalRead, NumRead);
end;
Result := (TotalRead > 0);
end;

begin
SetLength(Buf, 30);

Buf[0] = #254;
Buf[1] = #253;
Buf[2] = #0
Buf[3] = #224
Buf[4] = #235;
Buf[5] = #45;
Buf[6] = #14;
Buf[7] = #20
Buf[8] = #1;
Buf[9] = #11;
Buf[10] = #1;
Buf[11] = #5;
Buf[12] = #8;
Buf[13] = #10;
Buf[14] = #51;
Buf[15] = #52;
Buf[16] = #53;
Buf[17] = #19;
Buf[18] = #4;
Buf[19] = #54;
Buf[20] = #55;
Buf[21] = #56;
Buf[22] = #57;
Buf[23] = #20;
Buf[24] = #58;
Buf[25] = #59;
Buf[26] = #60;
Buf[27] = #61;
Buf[28] = #0;
Buf[29] = #0;

UDP1.Host := '217.44.119.250';
UDP1.Port := 5121;
UDP1.Connect;
try
UDP1.Send(Buf);
SetLength(Buf, 0);
if not Read(Buf, 5000) then
Memo1.Lines.Add('No response from server.')
else
Memo1.Lines.Add('Received: ' + BytesToString(Buf));
finally
UDP1.Disconnect;
end;
end;


Gambit





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Jan 13, 2005 5:42 pm    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote


"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote


Quote:
I can't actually get this to compile yet

Why not? You need to be more specific.

Quote:
what Indy compuntents should be under 'uses'?

IdGlobal, IdUDPClient


Gambit




Back to top
Dev
Guest





PostPosted: Thu Jan 13, 2005 6:41 pm    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote

Here's all the code using Delphi 2005 '.NET VCL Forms Application' compile
errors are below the code...

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdGlobal, IdSocketHandle, IdBaseComponent, IdComponent,
IdUDPBase,
IdUDPClient, Borland.Vcl.StdCtrls, System.ComponentModel,
IdIOHandlerStream,
IdIOHandlerStack, IdCustomTransparentProxy, IdIOHandlerSocket, IdSocks;

type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
UDP1: TIdUDPClient;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.nfm}

function Read(var VBytes: TIdBytes; ATimeout: Integer): Boolean;
var
RecvBuf: TIdBytes;
NumRead, TotalRead, Offset: Integer;
begin
TotalRead := 0;
SetLength(RecvBuf, 1024);
37 while TIdUDPClient.Binding.Readable(ATimeout) do
//ERROR 2233
begin
39 NumRead := TIdUDPClient.Binding.Receive(RecvBuf);
//ERROR 2233
if NumRead < 1 then Break;
Offset := Length(VBytes);
SetLength(VBytes, Offset + NumRead);
CopyTIdBytes(RecvBuf, 0, VBytes, Offset, NumRead);
Inc(TotalRead, NumRead);
end;
Result := (TotalRead > 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Buf, RecvBuf: TIdBytes;
Read: Integer;

begin
SetLength(Buf, 30);

Buf[0] := 254;
Buf[1] := 253;
Buf[2] := 0;
Buf[3] := 224;
Buf[4] := 235;
Buf[5] := 45;
Buf[6] := 14;
Buf[7] := 20;
Buf[8] := 1;
Buf[9] := 11;
Buf[10] := 1;
Buf[11] := 5;
Buf[12] := 8;
Buf[13] := 10;
Buf[14] := 51;
Buf[15] := 52;
Buf[16] := 53;
Buf[17] := 19;
Buf[18] := 4;
Buf[19] := 54;
Buf[20] := 55;
Buf[21] := 56;
Buf[22] := 57;
Buf[23] := 20;
Buf[24] := 58;
Buf[25] := 59;
Buf[26] := 60;
Buf[27] := 61;
Buf[28] := 0;
Buf[29] := 0;

88 UDP1.Connect; //ERROR 2003
try
UDP1.Send(Buf);
SetLength(Buf, 0);
92 if not Read(Buf, 5000) then //ERROR 2066 and ERROR
2012
Memo1.Lines.Add('No response from server.')
else
Memo1.Lines.Add('Received: ' + BytesToString(Buf));
finally
97 UDP1.Disconnect; //ERROR 2003
end;

end;

end.


[Error] Unit1.pas(37): E2233 Property 'Binding' inaccessible here
[Error] Unit1.pas(39): E2233 Property 'Binding' inaccessible here
[Error] Unit1.pas(8Cool: E2003 Undeclared identifier: 'Connect'
[Error] Unit1.pas(92): E2066 Missing operator or semicolon
[Error] Unit1.pas(92): E2012 Type of expression must be BOOLEAN
[Error] Unit1.pas(97): E2003 Undeclared identifier: 'Disconnect'

Would this be easy to translate to win32 as well instead of .net, I prefer
win32.

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote in message
news:41e64cc5 (AT) newsgroups (DOT) borland.com...

I can't actually get this to compile yet

Why not? You need to be more specific.

what Indy compuntents should be under 'uses'?

IdGlobal, IdUDPClient


Gambit






Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Jan 13, 2005 7:19 pm    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote


"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote


Quote:
37 while TIdUDPClient.Binding.Readable(ATimeout) do

Change that to the following:

while UDP1.Binding.Readable(ATimeout) do

Quote:
39 NumRead := TIdUDPClient.Binding.Receive(RecvBuf);

Change that to the following:

NumRead := UDP1.Binding.Receive(RecvBuf);

Quote:
88 UDP1.Connect; //ERROR 2003

There is nothing wrong with that. TIdUDPClient does have a public Connect()
method. The compiler error is wrong. What version of Indy 10 are you
actually using?

Quote:
92 if not Read(Buf, 5000) then //ERROR 2066 and ERROR
2012


Try changing the name of the inner function to something more unique, such
as ReadFromUDP() or whatever you want.

Quote:
97 UDP1.Disconnect; //ERROR 2003

There is nothing wrong with that. TIdUDPClient does have a public
Disconnect() method. The compiler error is wrong.

Quote:
Would this be easy to translate to win32 as well instead of .net,
I prefer win32.

The code will be the same for both Win32 and .NET.


Gambit



Back to top
Dev
Guest





PostPosted: Thu Jan 13, 2005 11:10 pm    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote

Let me get Delphi 7 back on here and Indy 10 installed with it and I'll see
if that helps


Back to top
Dev
Guest





PostPosted: Thu Jan 13, 2005 11:59 pm    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote

Delphi 7, Latest version of Indy 10.52 think it is or 10.0.52...

in the function Read, you said change TIdUDPClient.Binding...etc to
UDP1.Binding...etc it prefers the first way, the second way I get another
error stating UDP1 has not been identified. All except this the errors
before are the same. Still won't compile...

Any more ideas of solving this one, I would say stuff it I'll do it in C or
C++ but I like Delphi a lot more.

"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote

Quote:
Let me get Delphi 7 back on here and Indy 10 installed with it and I'll
see if that helps




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Jan 14, 2005 1:22 am    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote


"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote


Quote:
in the function Read, you said change TIdUDPClient.Binding...etc
to UDP1.Binding...etc it prefers the first way, the second way I
get another error stating UDP1 has not been identified.

That is not true. Read() is an inner function of Button1Click(), which is a
member of TForm1. Inner functions have access to everything that their
containing function has access to. UDP1 is a member of TForm1, and thus is
accessible to Button1Click(), and thus to Read() as well. But fine, if it
wants it to be declared explicitally, then so be it:

procedure TForm1.Button1Click(Sender: TObject);
var
Buf, RecvBuf: TIdBytes;
Read: Integer;

function ReadFromBinding(ABinding: TIdSocketHandle; var VBytes:
TIdBytes; ATimeout: Integer): Boolean;
var
RecvBuf: TIdBytes;
NumRead, TotalRead, Offset: Integer;
begin
TotalRead := 0;
SetLength(RecvBuf, 1024);
while ABinding.Readable(ATimeout) then begin
NumRead := ABinding.Receive(RecvBuf);
if NumRead < 1 then Break;
Offset := Length(VBytes);
SetLength(VBytes, Offset + NumRead);
CopyTIdBytes(RecvBuf, 0, VBytes, Offset, NumRead);
Inc(TotalRead, NumRead);
end;
Result := (TotalRead > 0);
end;

begin
SetLength(Buf, 30);

Buf[0] = #254;
Buf[1] = #253;
Buf[2] = #0
Buf[3] = #224
Buf[4] = #235;
Buf[5] = #45;
Buf[6] = #14;
Buf[7] = #20
Buf[8] = #1;
Buf[9] = #11;
Buf[10] = #1;
Buf[11] = #5;
Buf[12] = #8;
Buf[13] = #10;
Buf[14] = #51;
Buf[15] = #52;
Buf[16] = #53;
Buf[17] = #19;
Buf[18] = #4;
Buf[19] = #54;
Buf[20] = #55;
Buf[21] = #56;
Buf[22] = #57;
Buf[23] = #20;
Buf[24] = #58;
Buf[25] = #59;
Buf[26] = #60;
Buf[27] = #61;
Buf[28] = #0;
Buf[29] = #0;

UDP1.Host := '217.44.119.250';
UDP1.Port := 5121;
UDP1.Connect;
try
UDP1.Send(Buf);
SetLength(Buf, 0);
if not ReadFromBinding(UDP1.Binding, Buf, 5000) then
Memo1.Lines.Add('No response from server.')
else
Memo1.Lines.Add('Received: ' + BytesToString(Buf));
finally
UDP1.Disconnect;
end;
end;


Gambit



Back to top
Dev
Guest





PostPosted: Fri Jan 14, 2005 11:10 am    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote

There's good news and theirs bad news...

Good News: The code compiles beautifully.
Bad News: It's still not doing the job, instead of throwing out the longish
string it's ment to into Memo1.Lines it's putting nothing into it. What
could cause perfectly written code to give a this? Could the server return a
character / hex byte that terminates the code or causes the string to equal
nothing?


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Jan 14, 2005 9:15 pm    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote


"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote


Quote:
It's still not doing the job, instead of throwing out the longish string
it's ment to into Memo1.Lines it's putting nothing into it. What could
cause perfectly written code to give a this?

I cannot answer that because you did not provide any details at all. Does
ReadFromBinding() return True or False? If True, what is the Length() of
the returned TIdBytes data, and what the data actually contain? If False,
is it failing because Readable() never returns True or because Receive()
returns 0 bytes?

Quote:
Could the server return a character / hex byte that terminates the
code or causes the string to equal nothing?

No. The only thing that terminates the code is if the server does not send
any data at all. Now, you are using UDP afterall, so data loss is always a
possibility.


Gambit



Back to top
Dev
Guest





PostPosted: Fri Jan 14, 2005 11:36 pm    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote

Sorry Remy,

ReadFromBinding is returning true but I get nothing all Memo1.Lines contains
is 'Received: ' however by making the changes below:

From This...
SetLength(Buf,0);
if not ReadFromBinding(UDP1.Binding,Buf,5000) then
Memo1.Lines.Add('No response from server.')
else
Memo1.Lines.Add('Received: ' + BytesToString(Buf));
finally
UDP1.Disconnect;


To This
SetLength(Buf,255);
if not ReadFromBinding(UDP1.Binding,Buf,5000) then
Memo1.Lines.Add('No response from server.')
else
Memo1.Lines.Add('Received: ' + BytesToString(Buf));
finally
UDP1.Disconnect;

I receive this in Memo1.Lines 'Received: şı', the return is far too short
and contains no actual information like it should do when sniffed through
ethereal (see previos posting). I find it a little strange that it returns
some characters when I change the length of 'Buf', maybe this suggests
ReadFromBinding is not working as it was intended.

-----------------------------------------------------
Dev, Delphi Forums http://delphi.blue-aura.co.uk
-----------------------------------------------------

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote in message
news:41e7a8a9 (AT) newsgroups (DOT) borland.com...

It's still not doing the job, instead of throwing out the longish string
it's ment to into Memo1.Lines it's putting nothing into it. What could
cause perfectly written code to give a this?

I cannot answer that because you did not provide any details at all. Does
ReadFromBinding() return True or False? If True, what is the Length() of
the returned TIdBytes data, and what the data actually contain? If False,
is it failing because Readable() never returns True or because Receive()
returns 0 bytes?

Could the server return a character / hex byte that terminates the
code or causes the string to equal nothing?

No. The only thing that terminates the code is if the server does not
send
any data at all. Now, you are using UDP afterall, so data loss is always
a
possibility.


Gambit





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Jan 14, 2005 11:49 pm    Post subject: Re: Please help Indy 10 Delphi 2005 Reply with quote


"Dev" <gregz0012 (AT) hotmail (DOT) com> wrote


Quote:
by making the changes below:

From This...
SetLength(Buf,0);
snip
To This
SetLength(Buf,255);
snip


Do not do that. The length of the buffer was being set to 0 intentionally.
Otherwise, the buffer will still contain the original data that was sent
out, and as such the response data will be appended to the existing buffer
data rather than overwriting it.

Quote:
I receive this in Memo1.Lines 'Received: şı', the return is far too short
and contains no actual information like it should do when sniffed through
ethereal (see previos posting). I find it a little strange that it returns
some characters when I change the length of 'Buf'

That is because by changing the Length, the original contents are not
getting disgarded before then reading the response.

Quote:
maybe this suggests ReadFromBinding is not working as it was intended.

That is why I asked you earlier to specify what the actual Length of the
returned buffer is, and what its actual contents are. You did not answer
those questions.

SetLength(Buf, 0);
ReadFromBinding(UDP1.Binding, Buf, 5000)
// what does Length(Buf) return after ReadFromBinding() exits?
// if > 0, what are the actual bytes inside of Buf?

Gambit



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.