There is an application server, there is an application client, on the first one a file is sent to the client. Everything works, but I would like the newsletter to be sent not to one client, but to all connected ones.

I tried through the cycle, but since the file is split during the second cycle pass, an error appears in accessing the file I wanted to do it through sleep, but I thought for a long time and realized that it would not work. Which way to look? I do not want to go away from the sockets, with them at least the main function works.

I attach the link to the GIT https://github.com/WOLF33/EasyLan-v5.git

Closed due to the fact that off-topic participants Pavel Mayorov , zRrr , VenZell , D-side , aleksandr barakin 8 Jun '16 at 14:26 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - zRrr, VenZell, aleksandr barakin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • In combat operation, even this code will periodically lead to data corruption. You did not pay attention to the phrase in my answer to the previous question: the методы отправки данных в сокет и получения их из сокета - это функции и они возвращают количество реально прочитанных/записанных данных. - kami
  • I have a term paper, pass it once and forget, the main thing is to work 1 time. It turns out not to realize this opportunity? - Maxim Kutenkov
  • one
    "but since the file is broken during the second pass" - well, so do not break it! ) - Kromster
  • and if you don’t break it, then it just doesn’t come in safe and sound - Maxim Kutenkov

1 answer 1

You need to run a stream for each client to transfer the file. In order for each stream to read the file regardless of the others and without disturbing the others, you need to create your TFileStream in each stream without blocking reading this file for other streams. For example, like this:

 FS := TFileStream.Create( CreateFile(PChar('filename'), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0) ); 

And then each thread reads the file independently of the others and transfers it to its client.

  • if by threads you mean TThread , then the author has a non-blocking mode of the socket. It uses an event mechanism, not streams. But in general - yes, for each connection - you need a separate TStream . - kami
  • @kami yes, I meant the executing threads. There is not a word in the question about events. In this case, you need to create a packet of file streams in the main stream and handle events accordingly. - kot-da-vinci
  • @ kot-da-vinci Can I tell you more about threads? where exactly to add the code and which one? - Maxim Kutenkov
  • @MaksimKutenkov What code and where to write - you decide. What specifically about threads do you want to know? - kot-da-vinci
  • @ kot-da-vinci The code that you gave, as I understood it, needs to be written to the stream creation handler, but how can I then access each thread to send all the files to each client? - Maxim Kutenkov