* * *

Author Topic: Socket server program no response when using fprecv?  (Read 151 times)

Jonvy

  • Newbie
  • Posts: 4
Socket server program no response when using fprecv?
« on: April 12, 2018, 02:30:52 pm »
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'.


 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus