Hello,
I am trying to put simple multicast sender and receiver applications
together using ICS. The ICS receiver works fine when I use the Indy
Multicast server to send to it, but when I send using ICS TWSocket I only
receive on one of my receivers, or sometimes none. I am running receivers on
several PCs and occasionally with several instances on the same PC.
I am using Delphi 2007 and the current v5 release of ICS (downloaded today).
Any clues gratefully welcomed!
Regards,
Graham
The code I use to create the sender and send data is below.
//-------------------------------------------------------------------
procedure TForm4.OpenWSServerBtnClick(Sender: TObject);
begin
CloseWSServerBtnClick(Sender);
WSocketServer := TWSocket.create(Self);
//set values
WSocketServer.Proto := 'udp';
WSocketServer.MultiCast := true;
WSocketServer.MultiCastIpTTL := 1;
WSocketServer.MultiCastAddrStr := ServerBroadcastEdit.Text; //234.4.4.4
WSocketServer.Addr := ServerNICEdit.text; //192.168.34.10
WSocketServer.Port := ServerPort.Text; //33241
WSocketServer.LocalAddr := ServerNICEdit.text; //192.168.34.10
WSocketServer.ComponentOptions := [wsoNoReceiveLoop];
WSocketServer.OnChangeState := ServerStateChanged;
WSocketServer.OnSessionConnected := ServerConnected;
WSocketServer.OnDataAvailable := ServerDataAvalable;
//open
WSocketServer.Connect;
end;
procedure TForm4.SendWSBtnClick(Sender: TObject);
var
fData : array[0..1023] of char;
begin
StrpCopy(@fData[0], Edit1.Text);
WSocketServer.Send(@FData[0], Length(fData));
end;
//-------------------------------------------------------------------
The code I use to create the receiver and display the incoming data is
below.
//-------------------------------------------------------------------
procedure TForm4.OpenWSClientBtnClick(Sender: TObject);
begin
CloseWSClientBtnClick(Sender);
WSocketClient := TWSocket.Create(Self);
//set values
WSocketClient.OnDataAvailable := ClientDataAvalable;
WSocketClient.OnSessionConnected := ClientConnected;
WSocketClient.OnChangeState := ClientStateChanged;
WSocketClient.Proto := 'udp';
WSocketClient.MultiCast := true;
WSocketClient.MultiCastAddrStr := ClientBroadcastEdit.Text; //234.4.4.4
WSocketClient.Addr := ClientNICEdit.text; //192.168.34.10
WSocketClient.Port := ClientPort.Text; //33241
WSocketClient.LocalAddr := ClientNICEdit.text; //192.168.34.10
WSocketClient.ReuseAddr := true;
//open
WSocketClient.Listen;
end;
procedure TForm4.ClientDataAvalable(Sender: TObject; ErrCode: Word);
var
Count: integer;
Rcvd: array[0..8191] of char;
begin
if Error <> 0 then
Exit;
with Sender as TWSocket do
Count := Receive(@Rcvd[0], High(Rcvd));
if Count <= 0 then
Exit;
// Here handle the received data
RCvd[Count] := #0;
ClientMemo.Lines.Add(Trim(StrPas(PChar(@Rcvd[0]))));
end;
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be