Ho scritto i seguenti due progetti:
Server:
codice:var Form2: TForm2; HHost: string; implementation {$R *.dfm} procedure TForm2.AddLog(Text: string); begin Log.Lines.Add(TimeToStr(Now) + ': ' + Text); end; procedure TForm2.ConnBtnClick(Sender: TObject); begin if FileExists('local') then HHost := IP.CurrentIP else HHost := '192.168.0.2'; Server.Active := true; end; procedure TForm2.SendBtnClick(Sender: TObject); begin Server.Send(IP.CurrentIP, 1718, Cmd.Text); end; procedure TForm2.ServerUDPRead(Sender: TObject; AData: TBytes; ABinding: TIdSocketHandle); begin AddLog(ABinding.IP + ' -> ' + BytesToString(AData)); end; procedure TForm2.TimerTimer(Sender: TObject); begin if Server.Active then begin StatusLbl.Caption := 'Connesso.' + HHost; if not SendBtn.Enabled then SendBtn.Enabled := true; end else begin StatusLbl.Caption := 'Non connesso.'; if SendBtn.Enabled then SendBtn.Enabled := false; end; end; end.
Client:
Sia il client che il server funzionano sulla stessa macchina.codice:var Form3: TForm3; implementation {$R *.dfm} procedure TForm3.AddLog(Text: string); begin Log.Lines.Add(TimeToStr(Now) + ': ' + Text); end; procedure TForm3.ConnBtnClick(Sender: TObject); begin if FileExists('local') then Client.Host := IP.CurrentIP else Client.Host := '192.168.0.1'; Client.Connect; end; procedure TForm3.SendBtnClick(Sender: TObject); begin Client.Send(IP.currentIP,1717,Cmd.Text); end; procedure TForm3.TimerTimer(Sender: TObject); begin if Client.Connected then begin StatusLbl.Caption := 'Connesso' + Client.Host; if not SendBtn.Enabled then SendBtn.Enabled := true; end else begin StatusLbl.Caption := 'Non connesso'; if SendBtn.Enabled then SendBtn.Enabled := false; end; if Client.Binding.Readable(1) then AddLog(Client.Binding.PeerIP + ' -> ' + Client.ReceiveString()); end; end.
Si connettono correttamente, il Server su CurrentIP:1717 e manda dati su CurrentIP:1718 mentre il Client l'opposto.
Il problema è che il client invia correttamente al server, ma non avviene il contrario, che cosa ho sbagliato?????![]()
Aiutatemi x favore, grazie![]()
![]()

Rispondi quotando