 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bo Berglund Guest
|
Posted: Mon Sep 15, 2003 12:05 pm Post subject: How to use TUdpSocket (D7 Pro)?? |
|
|
I must write a Delphi app that can communicate with a third party
machine that is connected to the LAN using sockets. The machine
accepts connection requests through an UDP channel and if
authenticated will by itself connect to my program using TCP. The
problem is the UDP part, I cannot get the damn thing working in
Delphi...
I have a working example in VB6 using the MS Winsock component, but
obviously I don't like to use VB.
The VB code looks like this (simplified):
To start the UDP channel:
socketUDP.Protocol = sckUDPProtocol
socketUDP.RemotePort = 19284
socketUDP.RemoteHost = "TheMachineName"
socketUDP.Bind 19284
In the socket DataArrival Event:
Dim ReceiveText As String
socketUDP.GetData ReceiveText, vbString, bytesTotal
'Do something with the ReceiveText string
To send data out:
socketUDP.SendData Message
In Delphi 7 I have tried with this on a TUdpSocket component:
To start the UDP channel:
sckUDP.RemoteHost := TheMachineName;
sckUDP.RemotePort := '19284';
sckUDP.LocalPort := '19284';
sckUDP.Open;
To receive text in the OnReceive event (not working, it is not even
fired):
procedure TfrmComm.sckUDPReceive(Sender: TObject; Buf: PAnsiChar; var
DataLen: Integer);
var
sRxData: string;
begin
SetLength(sRxData,DataLen);
sckUDP.ReceiveBuf(sRxData[1],DataLen);
Memo1.Lines.Add(sRxData);
end;
I know that the machine is sending, because as soon as I fire up the
VB6 test app it starts displaying the received messages.
What do I need to do to get data into the UDP component?
Is there a working example anywhere? As usual the Delphi help is of no
use. It even seems to have text referring to another type of socket
sometimes...
Grateful for any help!
/Bo
|
|
| Back to top |
|
 |
|
|
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
|
|