Re: [twsocket] Sending a mix of text and records through TWSocket
At 09.33 27/10/2005 +0200, you wrote: Hello Geppy, I send the command and the record without waiting any reply from server. Yes, but I'm thinking over and it should work. TCP respect data sequence so cannot be any problem. As soon as server get's the command (and data len with it I suppose), he switch linemode off, and set IsRcvdBin to True. So the code part you posted should work. Was the original example not with client + server to test ? Hi Wilfried, no, your example (http://users.pandora.be/sonal.nv/ics/demos/Server1.zip) does not include the client. I tried with a modified ono included in ICS suite (Client7) and the send code is the one I posted with my first message. Maybe I'm missing the obvious... but I'm a newbie in socket programming, the ICS socket components are new to me. You know... after hours studying and trying a lot of different approaches (Indy, ICS, multithread, etc.) I got confused and I'm pretty sure I already have the solution in my head but I'm not able to code it ;) Thank you again Wilfried. Ciao. -- Geppy Piloni -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending a mix of text and records through TWSocket
At 13.16 27/10/2005 +0200, you wrote: Hello Geppy, Here is a working client example for this server: [SNIP] --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Hi Wilfried, first of all, thank you for your time and help :) Things are going better... Now the server socket receive the data form your client (even if I'm still trying to understand what was wrong with my previous one...) but now I think I'm doing something wrong while I try to transfer the buffer from socket to my record. In your server1 example, I modified the ReceiveBinComplete method of TClient as follows: procedure TClient.ReceiveBinComplete; var data : TData; begin Log(ltSystem, IntToStr(RcvdCount) + ' bytes received'); WritePtr := 0; // get ready for next receive IsRcvBin := False; // receiving of data is done LineMode := True;// we are going back to command mode SendStr('+OK DATA'#13#10); // tell the transmitter we have all data Move(Rcvd^, Data, SizeOf(Data)); // Rcvd is the pointer to the buffer Log(ltRx, 'data.name = ' + data.Name); Log(ltRx, 'data.ID = ' + IntToStr(data.ID)); end; but it returns an empty record. I don't understand why I get the exact length of received data (RcvdCount is 15, which is SizeOf(Data)) but Rcvd seems to point to an empty buffer. Maybe my pointer dereferencing code is wrong? Or should I need to use another function instead of Move()? Ciao. -- Geppy Piloni -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending a mix of text and records through TWSocket
Geppy Piloni wrote: data Move(Rcvd^, Data, SizeOf(Data)); // Rcvd is the pointer to the Should be Move(Rcvd^, Data, SizeOf(TData)); Length of the record Data instead of length of the variable. Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending a mix of text and records through TWSocket
In your server1 example, I modified the ReceiveBinComplete method of TClient as follows: procedure TClient.ReceiveBinComplete; var data : TData; begin Log(ltSystem, IntToStr(RcvdCount) + ' bytes received'); WritePtr := 0; // get ready for next receive IsRcvBin := False; // receiving of data is done LineMode := True;// we are going back to command mode SendStr('+OK DATA'#13#10); // tell the transmitter we have all data Move(Rcvd^, Data, SizeOf(Data)); // Rcvd is the pointer to the buffer Log(ltRx, 'data.name = ' + data.Name); Log(ltRx, 'data.ID = ' + IntToStr(data.ID)); end; but it returns an empty record. I don't understand why I get the exact length of received data (RcvdCount is 15, which is SizeOf(Data)) but Rcvd seems to point to an empty buffer. Maybe my pointer dereferencing code is wrong? Or should I need to use another function instead of Move()? Finally I solved my problem and the solution was obviously the simplest ;) There was this line in Wilfried's client code I didn't notice: FillChar(Data, SizeOf(TData), 0); I was filling my record before executing this line... That's why I received an empty one. Thank you guys for your help :) -- Geppy Piloni -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending a mix of text and records through TWSocket
Hello Geppy, FillChar(Data, SizeOf(TData), 0); Sorry for that. I have habitude to get rid of compiler warnings, even in a short demo where in this case it was not needed :( I'm glad it works for you now :) 1 additional note. You can also receive direct in your record. This save an additional copy of the received binary data. eg: RcvdBuf: array[0..8191] of char; MyRecord: TMyRecord absolute RcvdBuf; Both start at same address. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending a mix of text and records through TWSocket
Geppy, It would be helpful to see how you are receiving it. Show us some code on the receive side of this. Kirk On 10/26/05, Geppy Piloni [EMAIL PROTECTED] wrote: Hi all, I'm trying to implement the client server architecture described here: http://tinyurl.com/benop My first approach was with Indy 10, but after some attempts, I found quite difficult to manage the complexity of multithread programming, so I dropped Indy and now I'm trying ICS. I had a positive experience with ICS HTTP and mail components some years ago and I feel more comfortable with event handling than multithreading... I found a very useful example here http://tinyurl.com/cqkmh , Server1.zip: thank you Wilfried :) I studied also the ICS FAQ about receiving high speed data http://tinyurl.com/762c6 Starting from various TCP client inlcuded in ICS examples, I tried to send through TWSocket a mix of text commands and records but I wasn't successful. Assuming a given record and his pointer... PTMyRec = ^TMyRec; TMyRec = packed record .. .. end; ... and following the protocol implemented in the above mentioned example (server1.zip) I'm trying to send a text command followed by a record. I tried this way from a generic client: var pr : PTMyRec; r : TMyRec; begin wsocket.LineMode := True; WSocket.SendStr(EditCommand.Text + #13#10); // the command is 'DATA ' // r fields filled with some data pr := @r; wsocket.LineMode := False; wsocket.Send(pr, SizeOf(r)); end; On the server, I receive correctly the text command but not the record. What I'm doing wrong? Thank you in advance for your replies. -- Geppy Piloni -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending a mix of text and records through TWSocket
Hello Geppy, As Kirk and Arno mentioned show us how you receive the data. maybe one remark at the moment: wsocket.LineMode := True; WSocket.SendStr(EditCommand.Text + #13#10); // the command is 'DATA ' // r fields filled with some data pr := @r; wsocket.LineMode := False; wsocket.Send(pr, SizeOf(r)); Not needed to switch LineMode at the sender. TWSocket will only use lineMode whilst receivin. Also better to work event driven between the 2 applications: - send data whitch tell receiver you want to send a certain binary - receiver set linemode to false and answer 'ok i'm ready' - sender send the binary when he received the 'ok ready' - receiver say 'ok received' and switch lineMode back on - sender can go on now with next command if any on sender lineMode may be switched on all the time as he does only receive line based commands. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Wednesday, October 26, 2005, 19:09, Geppy Piloni wrote: Hi all, I'm trying to implement the client server architecture described here: http://tinyurl.com/benop My first approach was with Indy 10, but after some attempts, I found quite difficult to manage the complexity of multithread programming, so I dropped Indy and now I'm trying ICS. I had a positive experience with ICS HTTP and mail components some years ago and I feel more comfortable with event handling than multithreading... I found a very useful example here http://tinyurl.com/cqkmh , Server1.zip : thank you Wilfried :) I studied also the ICS FAQ about receiving high speed data http://tinyurl.com/762c6 Starting from various TCP client inlcuded in ICS examples, I tried to send through TWSocket a mix of text commands and records but I wasn't successful. Assuming a given record and his pointer... PTMyRec = ^TMyRec; TMyRec = packed record .. .. end; ... and following the protocol implemented in the above mentioned example (server1.zip) I'm trying to send a text command followed by a record. I tried this way from a generic client: var pr : PTMyRec; r : TMyRec; begin wsocket.LineMode := True; WSocket.SendStr(EditCommand.Text + #13#10); // the command is 'DATA ' // r fields filled with some data pr := @r; wsocket.LineMode := False; wsocket.Send(pr, SizeOf(r)); end; On the server, I receive correctly the text command but not the record. What I'm doing wrong? Thank you in advance for your replies. -- Geppy Piloni -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending a mix of text and records through TWSocket
Starting from various TCP client inlcuded in ICS examples, I tried to send through TWSocket a mix of text commands and records but I wasn't successful. On the server, I receive correctly the text command but not the record. What I'm doing wrong? You would need to be listening with LineMode = false to receive such mixed packets, but you don't really know how long to listen since there is no length sent anywhere. You should really devise a simple protocol that means you know how much data you are sending, and therefore how much to receive. The simplest improvement in your example would be work out the total length of string and record, send that length first, followed by a short string with length byte, then the binary record. Or just move the string into the record (as ShortString). You then know exactly how much data is being received, and can wait for as many packets as it takes. It will not necessarily arrive in a single packet. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be