Recent

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

Jonvy

  • New member
  • *
  • Posts: 24
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'.


Thaddy

  • Hero Member
  • *****
  • Posts: 7178
Re: Socket server program no response when using fprecv?
« Reply #1 on: May 12, 2018, 03:56:28 pm »
Stop spamming.
inline variables like in D10.3 are a bit like Brexit: if you are given the wrong information it sounds like a good idea. Every kid loves candy, but it makes you fat and your teeth will disappear.