Using address 0.0.0.0 instruct TWSocket to listen on all the interfaces in the computer. The alternative was to use only one of the IP adresses of the computer and then TWSocket would accepte connection originating only from that interface. You cannot set an IP address of an external device and ask TWSocket to listen on it !

--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be

----- Original Message ----- From: "zayin" <za...@pdq.net>
To: "'ICS support mailing'" <twsocket@elists.org>
Sent: Wednesday, March 24, 2010 1:55 PM
Subject: Re: [twsocket] UDP...


Hi,

Thanks.

I set the addr to 0.0.0.0, switched to SendTo and the reply was correct.

Since I will be communicating with many of these external devices I wanted
one TWSocket for each external device, that was why I set the addr field to
the external devices IP address. Using 0.0.0.0 it appears all the external
devices will reply through that one TWSocket and I will need to sort them
out in the OnDataAvaliable.

Is that correct?

Thanks,

Mark

-----Original Message-----
From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On
Behalf Of wilfried Mestdagh
Sent: Wednesday, March 24, 2010 3:03 AM
To: 'ICS support mailing'
Subject: Re: [twsocket] UDP...

Hi,

WSocket1.Addr:='192.168.1.2';
WSocket1.port:='9600';
I get an error 10049.
Means you cannot bind to that address. '192.168.1.2' is the address on the
remote machine, you can not listen on that.

The only difference I can see is the sending local port number is not
9600.

This should make no difference. You can set local port of course. There is a
property for that.

--
mvg, Wilfried
http://www.mestdagh.biz

-----Oorspronkelijk bericht-----
Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] Namens
zayin
Verzonden: woensdag 24 maart 2010 1:12
Aan: twsocket@elists.org
Onderwerp: [twsocket] UDP...

Hello,

I ran into this a couple years ago and I found a work around so I dropped
it. Now, new computer, new OS, new task. So, any reasons for my failure that
might have been computer/OS related are...

I am using Wireshark to verify what I am seeing.

Using D2007 and ICS version 5.25, UDP with TWSocket.

When I call 'Listen' after setting:

WSocket1.Addr:='192.168.1.2';
WSocket1.port:='9600';

I get an error 10049. Then of course if I send some bytes I get a 10057
error.

When I call 'Connect' after setting:

WSocket1.Addr:='192.168.1.2';
WSocket1.port:='9600';

I can send the bytes and Wireshark shows them as transmitted and I get a
reply from 192.168.1.2.

The reply I get back indicates there is an error in the bytes. I KNOW the
bytes are correct. The device also supports TCP with the same bytes and when I use TCP all is good. I have other software, I did not create, and it works
with UDP using the same byte stream.

The only difference I can see is the sending local port number is not 9600.
I am not sure why that matters. The software that does work does have a
local port number of 9600. And after hours, that is the only difference I
can see.

The source is below and I can upload a project if someone needs it.

Any ideas? What am I missing?

Ciao,

Mark

unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, WSocket, IcsLogger;

type
 TForm2 = class(TForm)
   Memo1: TMemo;
   WSocket1: TWSocket;
   ListenStartBtn: TButton;
   ListenStopBtn: TButton;
   Label1: TLabel;
   Label2: TLabel;
   ConnectStartBtn: TButton;
   StopConnectBtn: TButton;
   IcsLogger1: TIcsLogger;
   procedure ListenStartBtnClick(Sender: TObject);
   procedure WSocket1Error(Sender: TObject);
   procedure WSocket1SessionConnected(Sender: TObject; ErrCode: Word);
   procedure WSocket1SessionClosed(Sender: TObject; ErrCode: Word);
   procedure WSocket1DataAvailable(Sender: TObject; ErrCode: Word);
   procedure ListenStopBtnClick(Sender: TObject);
   procedure ConnectStartBtnClick(Sender: TObject);
 private
   holdingBuff:array [0..2048] of byte;
 public
   { Public declarations }
 end;

var
 Form2: TForm2;

implementation

{$R *.dfm}

var
outBuffer:array [0..17] of byte =
($80,$00,$02,$00,$02,$00,$00,$04,$00,$03,$01,$01,$B0,$00,$00,$00,$00,$01);

procedure TForm2.ConnectStartBtnClick(Sender: TObject);
begin
Memo1.Lines.Add('');
Memo1.Lines.Add('ConnectStartBtnClick');
WSocket1.Addr:='192.168.1.2';
WSocket1.port:='9600';
Memo1.Lines.Add('Connect');
WSocket1.Connect;
Memo1.Lines.Add('Send');
WSocket1.Send(@outBuffer,18);
end;

procedure TForm2.ListenStartBtnClick(Sender: TObject);
begin
Memo1.Lines.Add('');
Memo1.Lines.Add('ListenStartBtnClick');
WSocket1.Addr:='192.168.1.2';
WSocket1.port:='9600';
Memo1.Lines.Add('Listen');
WSocket1.Listen;
Memo1.Lines.Add('Send');
WSocket1.Send(@outBuffer,18);
end;

procedure TForm2.ListenStopBtnClick(Sender: TObject);
begin
Memo1.Lines.Add('Stop');
WSocket1.Close;
end;

procedure TForm2.WSocket1DataAvailable(Sender: TObject; ErrCode: Word);
var
byteCount:integer;
begin
if (ErrCode <> 0) then
 Memo1.Lines.Add('WSocket1DataAvailable: ' + IntToStr(ErrCode));

Memo1.Lines.Add('WSocket1DataAvailable');
byteCount:=WSocket1.Receive(@holdingBuff[0],sizeOf(holdingBuff));
if (byteCount < 1) then
 Exit;
Memo1.Lines.Add(IntToStr(byteCount));
end;

procedure TForm2.WSocket1Error(Sender: TObject);
begin
Memo1.Lines.Add('WSocket1Error: ' + IntToStr(WSocket1.LastError));
end;

procedure TForm2.WSocket1SessionClosed(Sender: TObject; ErrCode: Word);
begin
if (ErrCode <> 0) then
 Memo1.Lines.Add('WSocket1SessionClosed: ' + IntToStr(ErrCode));
Memo1.Lines.Add('WSocket1SessionClosed');
end;

procedure TForm2.WSocket1SessionConnected(Sender: TObject; ErrCode: Word);
begin
if (ErrCode <> 0) then
 Memo1.Lines.Add('WSocket1SessionConnected: ' + IntToStr(ErrCode));
Memo1.Lines.Add('WSocket1SessionConnected');
end;

end.

DFM---------------------------------------

object Form2: TForm2
 Left = 758
 Top = -807
 Caption = 'Form2'
 ClientHeight = 714
 ClientWidth = 667
 Color = clBtnFace
 Font.Charset = DEFAULT_CHARSET
 Font.Color = clWindowText
 Font.Height = -11
 Font.Name = 'Tahoma'
 Font.Style = []
 OldCreateOrder = False
 PixelsPerInch = 96
 TextHeight = 13
 object Label1: TLabel
   Left = 543
   Top = 104
   Width = 41
   Height = 19
   Caption = 'Listen'
   Font.Charset = DEFAULT_CHARSET
   Font.Color = clWindowText
   Font.Height = -16
   Font.Name = 'Tahoma'
   Font.Style = []
   ParentFont = False
 end
 object Label2: TLabel
   Left = 543
   Top = 232
   Width = 57
   Height = 19
   Caption = 'Connect'
   Font.Charset = DEFAULT_CHARSET
   Font.Color = clWindowText
   Font.Height = -16
   Font.Name = 'Tahoma'
   Font.Style = []
   ParentFont = False
 end
 object Memo1: TMemo
   Left = 8
   Top = 8
   Width = 529
   Height = 689
   ScrollBars = ssVertical
   TabOrder = 0
 end
 object ListenStartBtn: TButton
   Left = 543
   Top = 136
   Width = 75
   Height = 25
   Caption = 'Start'
   TabOrder = 1
   OnClick = ListenStartBtnClick
 end
 object ListenStopBtn: TButton
   Left = 543
   Top = 167
   Width = 75
   Height = 25
   Caption = 'Stop'
   TabOrder = 2
   OnClick = ListenStopBtnClick
 end
 object ConnectStartBtn: TButton
   Left = 543
   Top = 264
   Width = 75
   Height = 25
   Caption = 'Start'
   TabOrder = 3
   OnClick = ConnectStartBtnClick
 end
 object StopConnectBtn: TButton
   Left = 543
   Top = 295
   Width = 75
   Height = 25
   Caption = 'Stop'
   TabOrder = 4
   OnClick = ListenStopBtnClick
 end
 object WSocket1: TWSocket
   LineMode = False
   LineLimit = 65536
   LineEnd = #13#10
   LineEcho = False
   LineEdit = False
   Proto = 'udp'
   LocalAddr = '0.0.0.0'
   LocalPort = '0'
   LastError = 0
   MultiThreaded = False
   MultiCast = False
   MultiCastIpTTL = 1
   ReuseAddr = False
   ComponentOptions = []
   ListenBacklog = 5
   ReqVerLow = 1
   ReqVerHigh = 1
   OnDataAvailable = WSocket1DataAvailable
   OnSessionClosed = WSocket1SessionClosed
   OnSessionConnected = WSocket1SessionConnected
   OnError = WSocket1Error
   FlushTimeout = 60
   SendFlags = wsSendNormal
   LingerOnOff = wsLingerOn
   LingerTimeout = 0
   KeepAliveOnOff = wsKeepAliveOnSystem
   KeepAliveTime = 30000
   KeepAliveInterval = 1000
   SocksLevel = '5'
   SocksAuthentication = socksNoAuthentication
   Left = 568
   Top = 16
 end
 object IcsLogger1: TIcsLogger
   LogFileOption = lfoOverwrite
   LogFileName = 'C:\test.txt'
   LogOptions = [loDestEvent, loDestFile, loDestOutDebug, loAddStamp,
loWsockErr, loWsockInfo, loWsockDump, loSslErr, loSslInfo, loSslDump,
loProtSpecErr, loProtSpecInfo, loProtSpecDump]
   Left = 592
   Top = 528
 end
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

--
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

--
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

--
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

Reply via email to