Hi,
I've finally been able to restart a project from last October. Something
has gone missing and code that used to work doesn't anymore. So I have to
sort of start over. I've followed the example code, looked at my postings
from back then in the archives but I'm having problems with the following
sequence.
On FormShow I execute the following code:
if FirstTime then begin
SrvSocket.Proto := 'udp';
SrvSocket.Addr := '127.0.0.1'; // Use loopback
SrvSocket.Port := PortEdit.Text; // Wait on this port (4000).
SrvSocket.Listen; // Start listening for client
which also fires
//
OnSessionConnected.
FirstTime := FALSE;
PortEdit.Enabled := FALSE;
end;
As per the example in the FAQ I want to run this method when
'OnSessionAvailable' fires but it never happens. What's needed to make this
event fire? Running a client on that port (4000) doesn't seem to do
anything while sending UDP messages to that port from a client app does get
through.
I think I'm missing something critical but can't quite figure it out.
Thanks
John Dammeyer
procedure TForm1.SrvSocketSessionAvailable(Sender: TObject; ErrCode: Word);
var
NewHSocket : TSocket;
PeerName : TSockAddrIn;
Peer : String;
begin
PortEdit.Enabled := TRUE;
{ We need to accept the client connection }
NewHSocket := SrvSocket.Accept;
{ And then associate this connection with our client socket }
CliSocket.Dup(NewHSocket);
{ Wants to know who is connected to display on screen }
CliSocket.GetPeerName(PeerName, Sizeof(PeerName));
{ User likes to see internet address in dot notation }
Peer := IntToStr(ord(PeerName.sin_addr.S_un_b.s_b1)) + '.' +
IntToStr(ord(PeerName.sin_addr.S_un_b.s_b2)) + '.' +
IntToStr(ord(PeerName.sin_addr.S_un_b.s_b3)) + '.' +
IntToStr(ord(PeerName.sin_addr.S_un_b.s_b4));
InfoLabel.Caption := 'Remote ' + Peer +
' connected. Port:' + CliSocket.GetPeerPort;
{ Send a welcome message to the client }
//CliSocket.SendStr('Hello' + #13 + #10);
{ Enable the server user to disconect the client }
DisconnectButton.Enabled := TRUE;
InitDisplayButton.Enabled := TRUE;
end;
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be