Hello inhabitants and just very smart people from this site. I had a problem with writing code on Delphi ... I can not write part of the program for sending a text message with deferred reading. The client and server program itself - I wrote it ...

  • More details, please. Who, at what point and from where should I read? - avp
  • avp: if the server is running and the client is disconnected then writing a message to the client creates a temporary folder and a text file into which the message is placed after the client appears on the network, the text from the file is transferred to the client and the temporary file is deleted - danil
  • What's the problem? Immediately after loading, the client sends a request to the server to receive messages that were not delivered. The server is looking for messages for this user. Sends them to the client and marks them that they have already been read. Everything. - megacoder
  • uhh .. the problem is that i can't figure out how to write leather for this case ... i can't imagine what it should include ((( danil

2 answers 2

on the CLIENT, we describe the procedure of Send sending sending a message to Sender - the one who sends (for example, the user number), Message - the message itself

procedure Send(Sender : integer; Message : string); begin //отправка данных серверу //например строка в таком формате: //"From=" + IntToStr(Sender) + "#Mes=" + Message; end; 

on the SERVER, we describe the procedure Send send sending a message Receiver - the one who receives the message (for example, the user number), Message - the message itself

 procedure Send(Receiver : integer; Message : string); begin //отправка данных клиенту //например строка в таком формате: //"To=" + IntToStr(Receiver) + "#Mes=" + Message; end; 

on the SERVER, we describe the Accept function of receiving the Source message and its processing. it returns the message itself and in the From argument the number of the sending user

 function Accept(Source : string; var From : integer) : string; begin //получение текста сообщения и запись его в Source например из Socket. From := copy(Source, 6, pos('#', Source) - 6); delete(Source, 1, pos('#', Source) + 4); //+4 - нужно игнорировать "Mes=" и символ "#" - разделитель и всё что до него Result := Source; end; 

on CLIENT

the procedure that is performed immediately after entering the chat (or what do you have there?) UserId - user identification number:

 procedure Init(UserId : integer); begin Send(UserId, "loggedIn"); //процедура осведомляет сервер, чот пользователь он-лайн end; 

procedure for processing the received message on the server

 procedure ProcessRequest(From : integer; Message : string); begin if (Message = "loggedIn") then begin //сканирование папки с временными файлами - сообщениями для пользователя From. **n** - количество сообщений. запись сообщений в массив messages for i := 1 to n do begin Send(From, messages[i]); end; end else .... //другие случаи отправленных сообщений end; 

well, the CLIENT receives messages from the server as usual (nothing needs to be modified).

  • thank you so much))) for help) - danil

You can always always have a folder for each client. Transmitted messages are written to files in it. If the client is online, the server notifies him of a new message. Let the client read (transmitting commands to the server) files from there and remove them themselves (via the server).

Everything is simplified.

  • I apologize for a very immodest request, but how can I show this more clearly? if so possible a code snippet - danil
  • Well, unfortunately there is no code, this sentence is right from the head. But in general, you can look at the mail protocols (POP IMAP), but in my opinion there are no alerts in them. - avp