Fórum Problema com Socket (erro 10048) #297385
28/09/2005
0
Eu tento conectar.. blz, tudo certo..
fecho o cliente..
ao abrir denovo e tentar conectar.. ´Erro 10048, conexão já existente´
Não estou desconectando corretamente a fechar o cliente?
Têm como eu fechar todas as conexões? ou algo assim antes de conectar?
valeu
Amon-ra
Curtir tópico
+ 0Posts
28/09/2005
Crash
Gostei + 0
28/09/2005
Crash
ou ClientSocket.Socket.Disconnect;
Gostei + 0
29/09/2005
Amon-ra
Ocorre no cliente, isso que você falou eu já tentei não dá :(
Eu trato o erro.. aí peço pra desconectar e tentar denovo.. só que tenho q esperar um tempo sem executar o programa pra porta deixar de estar sendo usada.
Gostei + 0
29/09/2005
Martins
Ocorre no cliente, isso que você falou eu já tentei não dá :(
Eu trato o erro.. aí peço pra desconectar e tentar denovo.. só que tenho q esperar um tempo sem executar o programa pra porta deixar de estar sendo usada.[/quote:3931811eae]
Como é q vc tá fazendo a conexão e como está fechando? Posta aqui um pedaço dos códigos.
Gostei + 0
29/09/2005
Amon-ra
procedure Tlincenet.Button1Click(Sender: TObject); var teste : TTreeNode; begin try IdTCPClient1.Connect; except IdTCPClient1.IOHandler.Free; end; end; procedure Tlincenet.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin Application.ProcessMessages; IdTCPClient1.DisconnectSocket; IdTCPClient1.Disconnect; end;
É isso, por q é só um teste mesmo..
Aproveitando o servidor é assim:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin IdTCPServer1.Active := false; end; procedure TForm1.Timer1Timer(Sender: TObject); begin if IdTCPServer1.Active then begin end else begin end; end; procedure TForm1.Button1Click(Sender: TObject); begin if IdTCPServer1.Active = true then begin Button1.Caption := ´Conectar´; IdTCPServer1.Active := false; end else begin Button1.Caption := ´Desconectar´; IdTCPServer1.Active := true; end; end; procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread); var funcionando : boolean; temp : string; begin funcionando := true; while funcionando do begin try temp := AThread.Connection.ReadLn(); except funcionando := false; end; end; end; procedure TForm1.Button2Click(Sender: TObject); begin form2.Show; end; procedure TForm1.Button3Click(Sender: TObject); begin close; end;
Gostei + 0
29/09/2005
Massuda
Com relação ao seu código cliente, experimente fazer assim (não testei)...
procedure Tlincenet.Button1Click(Sender: TObject); var teste : TTreeNode; begin try IdTCPClient1.Connect; except // isto não é necessário! //IdTCPClient1.IOHandler.Free; end; end; procedure Tlincenet.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin // isto não é necessário! //Application.ProcessMessages; //IdTCPClient1.DisconnectSocket; IdTCPClient1.Disconnect; end;
Já o código do servidor tem um pequeno problema...
uses IdGlobal, ... procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread); var funcionando : boolean; temp : string; begin funcionando := true; while funcionando and not AThread.Stopped do begin try temp := AThread.Connection.ReadLn(LF, 500); except funcionando := false; end; end; end; ...
Gostei + 0
29/09/2005
Martins
procedure Tlincenet.Button1Click(Sender: TObject); var teste : TTreeNode; begin try IdTCPClient1.Connect; except // isto não é necessário! //IdTCPClient1.IOHandler.Free; end; end; procedure Tlincenet.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin // isto não é necessário! //Application.ProcessMessages; //IdTCPClient1.DisconnectSocket; IdTCPClient1.Disconnect; end;
uses IdGlobal, ... procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread); var funcionando : boolean; temp : string; begin funcionando := true; while funcionando and not AThread.Stopped do begin try temp := AThread.Connection.ReadLn(LF, 500); except funcionando := false; end; end; end; ...
Blz [b:8a10d2ecab]Massuda[/b:8a10d2ecab], até eu vou fazer uns testes aqui. Show de bola!!!!
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)