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