I write a program to receive data from socket client and display the data in edit control.
First time when I receive data, the program works well.
But for 2nd time, when I click 'receive text', the program will not work,and Windows show no response.
I can not find the reason, can any one help me?
code like this:
procedure TForm1.BtnTxtRecvClick(Sender: TObject);
var
ReceLen,i:integer;//Receive Length;
BlockBuf:array[0..BlockLen-1] of Byte;//Buffer Zone;
RecvSocket:longint;
ra:SOCKADDR_IN;//define SOCKADDR_IN var
ra_len:integer;//ra length
begin
ra_len:=sizeof(ra);
//Waiting connection from client
RecvSocket:=fpaccept(serverSocket,@ra,@ra_len);
//Receive Data
if RecvSocket<>-1 then
begin
ReceLen:=fprecv(RecvSocket,@BlockBuf[0],BlockLen,0);
i:=0;
while i<ReceLen do
begin
EdtReceive.Text:=EdtReceive.Text+Chr(BlockBuf);
Inc(i,1);
end;
fpShutDown(RecvSocket,2);
closeSocket(RecvSocket);
end;
end;
I attach all files here.
When using it,1st click but 'Listen', then after receiving data from socket,click button 'Receive Test'.