![]() |
Socket- Fehler
Hallo,
ich bekomme immer eine Fehlermeldung "Asynchroner Socket-Fehler 10038." ! Ist am Quelltext was falsch?
Delphi-Quellcode:
procedure TForm1.Button3Click(Sender: TObject);
var s : String; begin ClientSocket1.Port := 1234; ClientSocket1.Address := '192.168.0.1'; ClientSocket1.Active := true; try ClientSocket1.Open; s := String.Format('<event>'#10'<address>%s</address>'#10'<message>%s</message>'#10'</event>',['0000000','TEST']); ClientSocket1.Socket.SendText(s); finally ClientSocket1.Active := false; ClientSocket1.Socket.Close; ClientSocket1.Close; end; end; |
AW: Socket- Fehler
Warum erst
Delphi-Quellcode:
und dann
ClientSocket1.Active := true;
Delphi-Quellcode:
?
ClientSocket1.Open;
|
AW: Socket- Fehler
Hier noch ein anderes Beispiel!
Das Panel1. wird nicht gefärbt! Warum nicht?
Delphi-Quellcode:
unit Unit1;
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.StdCtrls, System.Win.ScktComp, WinSock; type TForm1 = class(TForm) Panel1: TPanel; CheckBox1: TCheckBox; CheckBox2: TCheckBox; firEmergency: TClientSocket; Panel2: TPanel; connect: TTimer; procedure CheckBox1Click(Sender: TObject); procedure connectTimer(Sender: TObject); procedure CheckBox2Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.CheckBox1Click(Sender: TObject); begin if CheckBox1.Checked = true then begin firEmergency.Port := 5555; firEmergency.Address := '127.0.0.1'; firEmergency.Active := true; CheckBox2.Enabled := false; end else begin firEmergency.Active := false; end; end; procedure TForm1.CheckBox2Click(Sender: TObject); begin if CheckBox2.Checked = true then begin firEmergency.Port := 5555; firEmergency.Address := '192.168.0.251'; firEmergency.Active := true; CheckBox1.Enabled := false; end else begin firEmergency.Active := false; end; end; procedure TForm1.connectTimer(Sender: TObject); begin if firEmergency.Active = true then begin Panel1.Color := $0080FF80; end else begin Panel1.Color := $008080FF; end; end; end. |
AW: Socket- Fehler
quatsch! mein Fehler! Panel2 !!!!!!!!!!!!!
|
AW: Socket- Fehler
Zitat:
|
AW: Socket- Fehler
Liste der Anhänge anzeigen (Anzahl: 2)
Hallo,
bekomme immer noch zwei Fehlermeldungen (siehe Anhang)! Was mache ich falsch?
Delphi-Quellcode:
unit Unit1;
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, WinSock, Vcl.StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure InitSockets; var Data: WSAData; Res: Integer; ErrorCode: Integer; S: String; Len: Integer; begin res := WSAStartup( makeWord(1,1), Data); if res = SOCKET_ERROR then begin ErrorCode := WSAGetLastError; Setlength(s,260); Len := Formatmessage(Format_Message_from_System, nil, errorCode, 0, @s[1], length(s), nil); Setlength(s, len); MessageBox(0, PChar(s), 'Socket Error', MB_OK or MB_ICONERROR or MB_TASKMODAL); end; end; procedure HandleError; var ErrorCode: Integer; S: String; Len: Integer; begin ErrorCode := WSAGetLastError; Setlength(s,260); Len := Formatmessage(Format_Message_from_System, nil, errorCode, 0, @s[1], length(s), nil); Setlength(s, len); MessageBox(0, PChar(s), 'Socket Error', MB_OK or MB_ICONERROR or MB_TASKMODAL); end; function createSocket_UDP: TSocket; begin result := socket(AF_INET,SOCK_STREAM,IPProto_UDP); if result = INVALID_SOCKET then HandleError; end; procedure sendbuf_via_UDP(IP:string; Port: Word; var buf; buflen: Integer); var SockAddr: TSockAddrIn; AddrLen: Integer; FSocket: TSocket; begin FSocket := createSocket_UDP; Addrlen := SizeOf(SockAddr); SockAddr.sin_family := AF_INET; SockAddr.sin_Port := htons(Port); SockAddr.sin_Addr.S_Addr := inet_addr(PAnsiChar(IP)); if Sendto( FSocket, buf, buflen, 0, SockAddr, AddrLen) = Socket_ERROR then HandleError; CloseSocket( FSocket); end; procedure TForm1.Button1Click(Sender: TObject); var MyString: String; begin MyString := 'test'; Sendbuf_via_UDP('192.168.0.251', 1234, MyString[1], length(MyString)); end; initialization Initsockets; finalization WSACleanup; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:21 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz