Re: [twsocket] UDP SendTo
Hello, This UDP stuff is driving me nuts. Maximum outbound (send) size of a message returned by getsockopt as described below is 65507 bytes on my w2k box. Up to this size datagrams go over the wire. However if I SendTo a bigger datagram up to 65527 bytes then SendTo happily returns success even though nothing was sent! At a datagram size of 65528 bytes however the function fails with WSAGetLastError returning WSAEMSGSIZE as stated in the M$ documentation, is this normal? Also, when I set the IP_DONTFRAGMENT flag before sending a datagram that would have being fragmented otherwise SendTo also happily returns success even though no data was sent. --- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html Arno Garrels wrote: > Hello, > > I would like to send datagrams thru SendTo() instead of > Send() in order to bypass copying data to TWSocket's send > buffer. When I call SendTo() I have to handle > possible errors by myself, but I do not understand > exactely whether it's possible that the function returns > a positive result smaller than Len. > > The online help says: > > "If no error occurs, sendto returns the total number of bytes > sent, which can be less than the number indicated by len." > > OK, but a little bit later: > > "For message-oriented sockets, care must be taken not to exceed > the maximum packet size of the underlying subnets, which can > be obtained by using getsockopt to retrieve the value of > socket option SO_MAX_MSG_SIZE. If the data is too long to pass > atomically through the underlying protocol, the error > WSAEMSGSIZE is returned and no data is transmitted." > > Does this mean that in UDP either any number of bytes is sent > or WSAEMSGSIZE is returned? > > > --- > Arno Garrels [TeamICS] > http://www.overbyte.be/eng/overbyte/teamics.html -- 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
[twsocket] UDP SendTo
Hello, I would like to send datagrams thru SendTo() instead of Send() in order to bypass copying data to TWSocket's send buffer. When I call SendTo() I have to handle possible errors by myself, but I do not understand exactely whether it's possible that the function returns a positive result smaller than Len. The online help says: "If no error occurs, sendto returns the total number of bytes sent, which can be less than the number indicated by len." OK, but a little bit later: "For message-oriented sockets, care must be taken not to exceed the maximum packet size of the underlying subnets, which can be obtained by using getsockopt to retrieve the value of socket option SO_MAX_MSG_SIZE. If the data is too long to pass atomically through the underlying protocol, the error WSAEMSGSIZE is returned and no data is transmitted." Does this mean that in UDP either any number of bytes is sent or WSAEMSGSIZE is returned? --- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- 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
Re: [twsocket] UDP SendTo() sends two packets?
Hello Jack, Do you send to a broadcast address or to a specific address ? Do you have 1 or 2 IP addresses in the sending machine ? --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Wednesday, May 3, 2006, 00:52, Jack wrote: > I have the code to listen on a UDP port when the first button > is clicked, and send a packet when the second button is clicked. > It works fine except when the second button is clicked, it sends > two packets (I captured that with Ethereal.) Is there anything > I'm not doing right? > -- > Best regards, > Jack > unit Unit1; > interface > uses > Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, > Dialogs, StdCtrls, WinSock, WSocket; > type > TForm1 = class(TForm) > WSocket1: TWSocket; > Memo1: TMemo; > Label1: TLabel; > Label2: TLabel; > btnSend: TButton; > edtDstIP: TEdit; > edtSvrPort: TEdit; > btnListen: TButton; > edtPort: TEdit; > procedure WSocket1DataAvailable(Sender: TObject; ErrCode: Word); > procedure btnSendClick(Sender: TObject); > procedure btnListenClick(Sender: TObject); > private > { Private declarations } > public > { Public declarations } > end; > var > Form1: TForm1; > implementation > {$R *.dfm} > procedure TForm1.btnListenClick(Sender: TObject); > begin > WSocket1.Proto := 'udp'; > WSocket1.Port := edtSvrPort.Text; > WSocket1.Addr := '0.0.0.0'; > WSocket1.Listen; > btnListen.Enabled := False; > end; > procedure TForm1.btnSendClick(Sender: TObject); > var Src: TSockAddrIn; SrcLen: Integer; > begin > Src.sin_family := AF_INET; > Src.sin_addr.S_addr := inet_addr(PChar(edtDstIp.Text)); > Src.sin_port := hToNs(StrToInt(edtPort.Text)); > SrcLen := SizeOf(Src); > WSocket1.SendTo(Src, SrcLen, PChar('Hello'), 5); > end; > procedure TForm1.WSocket1DataAvailable(Sender: TObject; ErrCode: Word); > begin > if ErrCode = 0 then Memo1.Lines.Add(WSocket1.ReceiveStr) > else Memo1.Lines.Add('WSocket1DataAvailable() error = ' + > IntToStr(ErrCode)); > end; > 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
Re: [twsocket] UDP SendTo() sends two packets?
I don't see anything obviously wrong. -- Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] http://www.overbyte.be - Original Message - From: "Jack" <[EMAIL PROTECTED]> To: "ICS support mailing" Sent: Wednesday, May 03, 2006 12:52 AM Subject: [twsocket] UDP SendTo() sends two packets? >I have the code to listen on a UDP port when the first button > is clicked, and send a packet when the second button is clicked. > It works fine except when the second button is clicked, it sends > two packets (I captured that with Ethereal.) Is there anything > I'm not doing right? > > -- > Best regards, > Jack > > > unit Unit1; > > interface > > uses > Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, > Forms, > Dialogs, StdCtrls, WinSock, WSocket; > > type > TForm1 = class(TForm) >WSocket1: TWSocket; >Memo1: TMemo; >Label1: TLabel; >Label2: TLabel; >btnSend: TButton; >edtDstIP: TEdit; >edtSvrPort: TEdit; >btnListen: TButton; >edtPort: TEdit; >procedure WSocket1DataAvailable(Sender: TObject; ErrCode: Word); >procedure btnSendClick(Sender: TObject); >procedure btnListenClick(Sender: TObject); > private >{ Private declarations } > public >{ Public declarations } > end; > > var > Form1: TForm1; > > implementation > > {$R *.dfm} > > procedure TForm1.btnListenClick(Sender: TObject); > begin > WSocket1.Proto := 'udp'; > WSocket1.Port := edtSvrPort.Text; > WSocket1.Addr := '0.0.0.0'; > WSocket1.Listen; > btnListen.Enabled := False; > end; > > procedure TForm1.btnSendClick(Sender: TObject); > var Src: TSockAddrIn; SrcLen: Integer; > begin > Src.sin_family := AF_INET; > Src.sin_addr.S_addr := inet_addr(PChar(edtDstIp.Text)); > Src.sin_port := hToNs(StrToInt(edtPort.Text)); > SrcLen := SizeOf(Src); > WSocket1.SendTo(Src, SrcLen, PChar('Hello'), 5); > end; > > procedure TForm1.WSocket1DataAvailable(Sender: TObject; ErrCode: Word); > begin > if ErrCode = 0 then Memo1.Lines.Add(WSocket1.ReceiveStr) > else Memo1.Lines.Add('WSocket1DataAvailable() error = ' + > IntToStr(ErrCode)); > end; > > 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 -- 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
[twsocket] UDP SendTo() sends two packets?
I have the code to listen on a UDP port when the first button is clicked, and send a packet when the second button is clicked. It works fine except when the second button is clicked, it sends two packets (I captured that with Ethereal.) Is there anything I'm not doing right? -- Best regards, Jack unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, WinSock, WSocket; type TForm1 = class(TForm) WSocket1: TWSocket; Memo1: TMemo; Label1: TLabel; Label2: TLabel; btnSend: TButton; edtDstIP: TEdit; edtSvrPort: TEdit; btnListen: TButton; edtPort: TEdit; procedure WSocket1DataAvailable(Sender: TObject; ErrCode: Word); procedure btnSendClick(Sender: TObject); procedure btnListenClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btnListenClick(Sender: TObject); begin WSocket1.Proto := 'udp'; WSocket1.Port := edtSvrPort.Text; WSocket1.Addr := '0.0.0.0'; WSocket1.Listen; btnListen.Enabled := False; end; procedure TForm1.btnSendClick(Sender: TObject); var Src: TSockAddrIn; SrcLen: Integer; begin Src.sin_family := AF_INET; Src.sin_addr.S_addr := inet_addr(PChar(edtDstIp.Text)); Src.sin_port := hToNs(StrToInt(edtPort.Text)); SrcLen := SizeOf(Src); WSocket1.SendTo(Src, SrcLen, PChar('Hello'), 5); end; procedure TForm1.WSocket1DataAvailable(Sender: TObject; ErrCode: Word); begin if ErrCode = 0 then Memo1.Lines.Add(WSocket1.ReceiveStr) else Memo1.Lines.Add('WSocket1DataAvailable() error = ' + IntToStr(ErrCode)); end; 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