Re: [twsocket] Sending font styles and colors over network
Thanks for the tips and information, is there any time that shows the correct way of implementing this ?, and am always looking for better more stable ways of sending and receiving data from sockets. Thanks -Original Message- From: Simon Lewis Sent: Saturday, December 06, 2014 11:18 AM To: TWSocket Archives Subject: Re: Sending font styles and colors over network Thanks for the Information am using TCP with custom process here code procedure TLobbyServer.SocketServerDataAvailable(Sender: TObject; ErrCode: Word); begin if ErrCode <> 0 then Exit; with Sender as TWSocketClient do begin RunCommand(ReceiveStr, Sender as TWSocketClient); end; end; procedure TLobbyServer.RunCommand(comdata: string; rSocket: TWSocketClient); var command: string; begin { INCOMING ENCODED DATA STRING } comdata := DecodeStr(comdata); { DECODE INCOMING DATA STRING } while DecodeCommand(comdata, command, dat) do begin case StrToIntDef(command, -1) of 00: begin LobbyChatMsgs(dat[0], dat[1], dat[2], dat[3], StrToInt(dat[4]), StrToInt(dat[5]), TFontStyles(Byte(StrToInt(dat[6]))), rSocket); end; end; end; procedure TLobbyServer.LobbyChatMsgs(const LobbyID: String; const UserName: String; const Msg: String; const FontName: String; FontColor: TColor; FontSize: Integer; const FontStyle: TFontStyles; rSocket: TWSocketClient); begin if Trim(UserName) = '' then begin Exit; end else begin SendLobbyCommand(LobbyID, 'š04œ' + LobbyID + 'œ' + UserName + 'œ' + Msg + 'œ' + FontName + 'œ' + IntToStr(FontColor) + 'œ' + IntToStr(FontSize) + 'œ' + FontStyletoStr(FontStyle) + 'œ'); end; end; any way to improve it?, I know it be hard reading code with no having all the correct codes so on also would you be able to supple me with a simple image stream demo for video I been looking all over for one and Never found it I would like to add video to my app one day ha. -Original Message- From: Simon Lewis Sent: Friday, December 05, 2014 6:53 PM To: TWSocket Archives Subject: Sending font styles and colors over network I know am flooding this news group with pointless questions but I really need to know, am building a chat system and I want to send basic text chat with font size/font color/font styles for each user am doing this via strings and sending to server and back to client but I noticed after a while and when more then a few users are typing the text chat becomes unstable and incorrect font styles / colors and sizes happen and only way to fix it is to re-login so am wondering what would be best way to send the information over network so it would be stable and reliable. Thanks -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending font styles and colors over network
Hi François oh... yes... I (once knew.. but totally) forgot about this feature... thanks. [ As soon as Simon will start to submit pics/sounds/files a.s.o. he might be happier with his own "inbuffer". ] Best regards Michael Am 06.12.2014 15:06, schrieb François Piette: You are right Michael. If Simon's protocol is a character oriented protocol, he may use the "LineMode" feature of TWSocket to assemble received data in line and trigger OnDataAvailable event only for each complete line. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending font styles and colors over network
You are right Michael. If Simon's protocol is a character oriented protocol, he may use the "LineMode" feature of TWSocket to assemble received data in line and trigger OnDataAvailable event only for each complete line. -- francois.pie...@overbyte.be Embarcadero MVP http://www.overbyte.be http://francois-piette.blogspot.com -Message d'origine- De : TWSocket [mailto:twsocket-boun...@lists.elists.org] De la part de Michael Gasser (privat) Envoyé : samedi 6 décembre 2014 13:35 À : ICS support mailing Objet : Re: [twsocket] Sending font styles and colors over network , Hi Simon did you read François Piettes posting, mainly the part about large "fragmented packets"? F.e. : - If a client sends a large packet A to your server, your client may receive it (in your proc SocketServerDataAvailable) in several "small" packets. - If a client machine sends several packages at once the data may arrive in several small packets. Example: C sends ABCDEF - the server may receive the data in four pieces: A1 (part 1 of A), then A2, then A3BCD1, then D2EF. *You must implement an "incoming data buffer" for each connection (*Maybe you did... (?)), and then pass this buffered data to your parser. Regards Michael Am 06.12.2014 12:18, schrieb Simon Lewis: > Thanks for the Information am using TCP with custom process here code > > procedure TLobbyServer.SocketServerDataAvailable(Sender: TObject; > ErrCode: Word); > begin > if ErrCode <> 0 then Exit; > with Sender as TWSocketClient do > begin >RunCommand(ReceiveStr, Sender as TWSocketClient); end; end; > > procedure TLobbyServer.RunCommand(comdata: string; rSocket: > TWSocketClient); > var > command: string; > begin > { INCOMING ENCODED DATA STRING } > comdata := DecodeStr(comdata); > { DECODE INCOMING DATA STRING } > while DecodeCommand(comdata, command, dat) do begin >case StrToIntDef(command, -1) of > 00: begin > LobbyChatMsgs(dat[0], dat[1], dat[2], dat[3], > StrToInt(dat[4]), StrToInt(dat[5]), > TFontStyles(Byte(StrToInt(dat[6]))), rSocket); > end; >end; > end; > > procedure TLobbyServer.LobbyChatMsgs(const LobbyID: String; const > UserName: String; const Msg: String; const FontName: String; > FontColor: TColor; FontSize: Integer; const FontStyle: TFontStyles; > rSocket: TWSocketClient); > begin > if Trim(UserName) = '' then > begin >Exit; > end else begin >SendLobbyCommand(LobbyID, 'š04œ' >+ LobbyID + 'œ' >+ UserName + 'œ' >+ Msg + 'œ' >+ FontName + 'œ' >+ IntToStr(FontColor) + 'œ' >+ IntToStr(FontSize) + 'œ' >+ FontStyletoStr(FontStyle) + 'œ'); >end; > end; > > any way to improve it?, I know it be hard reading code with no having > all the correct codes so on also would you be able to supple me with a > simple image stream demo for video I been looking all over for one and > Never found it I would like to add video to my app one day ha. > > -Original Message- From: Simon Lewis > Sent: Friday, December 05, 2014 6:53 PM > To: TWSocket Archives > Subject: Sending font styles and colors over network > > I know am flooding this news group with pointless questions but I > really need to know, am building a chat system and I want to send > basic text chat with font size/font color/font styles for each user am > doing this via strings and sending to server and back to client but I > noticed after a while and when more then a few users are typing the > text chat becomes unstable and incorrect font styles / colors and > sizes happen and only way to fix it is to re-login so am wondering > what would be best way to send the information over network so it > would be stable and reliable. > > Thanks -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending font styles and colors over network
Simon, your code wont properly work because it assume to receive one single and complete command at each OnDataAvailable event. That is complete wrong. See Michael's reply. -- francois.pie...@overbyte.be Embarcadero MVP http://www.overbyte.be http://francois-piette.blogspot.com -Message d'origine- De : TWSocket [mailto:twsocket-boun...@lists.elists.org] De la part de Simon Lewis Envoyé : samedi 6 décembre 2014 12:19 À : TWSocket Archives Objet : Re: [twsocket] Sending font styles and colors over network Thanks for the Information am using TCP with custom process here code procedure TLobbyServer.SocketServerDataAvailable(Sender: TObject; ErrCode: Word); begin if ErrCode <> 0 then Exit; with Sender as TWSocketClient do begin RunCommand(ReceiveStr, Sender as TWSocketClient); end; end; procedure TLobbyServer.RunCommand(comdata: string; rSocket: TWSocketClient); var command: string; begin { INCOMING ENCODED DATA STRING } comdata := DecodeStr(comdata); { DECODE INCOMING DATA STRING } while DecodeCommand(comdata, command, dat) do begin case StrToIntDef(command, -1) of 00: begin LobbyChatMsgs(dat[0], dat[1], dat[2], dat[3], StrToInt(dat[4]), StrToInt(dat[5]), TFontStyles(Byte(StrToInt(dat[6]))), rSocket); end; end; end; procedure TLobbyServer.LobbyChatMsgs(const LobbyID: String; const UserName: String; const Msg: String; const FontName: String; FontColor: TColor; FontSize: Integer; const FontStyle: TFontStyles; rSocket: TWSocketClient); begin if Trim(UserName) = '' then begin Exit; end else begin SendLobbyCommand(LobbyID, 'š04œ' + LobbyID + 'œ' + UserName + 'œ' + Msg + 'œ' + FontName + 'œ' + IntToStr(FontColor) + 'œ' + IntToStr(FontSize) + 'œ' + FontStyletoStr(FontStyle) + 'œ'); end; end; any way to improve it?, I know it be hard reading code with no having all the correct codes so on also would you be able to supple me with a simple image stream demo for video I been looking all over for one and Never found it I would like to add video to my app one day ha. -Original Message- From: Simon Lewis Sent: Friday, December 05, 2014 6:53 PM To: TWSocket Archives Subject: Sending font styles and colors over network I know am flooding this news group with pointless questions but I really need to know, am building a chat system and I want to send basic text chat with font size/font color/font styles for each user am doing this via strings and sending to server and back to client but I noticed after a while and when more then a few users are typing the text chat becomes unstable and incorrect font styles / colors and sizes happen and only way to fix it is to re-login so am wondering what would be best way to send the information over network so it would be stable and reliable. Thanks -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending font styles and colors over network
, Hi Simon did you read François Piettes posting, mainly the part about large "fragmented packets"? F.e. : - If a client sends a large packet A to your server, your client may receive it (in your proc SocketServerDataAvailable) in several "small" packets. - If a client machine sends several packages at once the data may arrive in several small packets. Example: C sends ABCDEF - the server may receive the data in four pieces: A1 (part 1 of A), then A2, then A3BCD1, then D2EF. *You must implement an "incoming data buffer" for each connection (*Maybe you did... (?)), and then pass this buffered data to your parser. Regards Michael Am 06.12.2014 12:18, schrieb Simon Lewis: Thanks for the Information am using TCP with custom process here code procedure TLobbyServer.SocketServerDataAvailable(Sender: TObject; ErrCode: Word); begin if ErrCode <> 0 then Exit; with Sender as TWSocketClient do begin RunCommand(ReceiveStr, Sender as TWSocketClient); end; end; procedure TLobbyServer.RunCommand(comdata: string; rSocket: TWSocketClient); var command: string; begin { INCOMING ENCODED DATA STRING } comdata := DecodeStr(comdata); { DECODE INCOMING DATA STRING } while DecodeCommand(comdata, command, dat) do begin case StrToIntDef(command, -1) of 00: begin LobbyChatMsgs(dat[0], dat[1], dat[2], dat[3], StrToInt(dat[4]), StrToInt(dat[5]), TFontStyles(Byte(StrToInt(dat[6]))), rSocket); end; end; end; procedure TLobbyServer.LobbyChatMsgs(const LobbyID: String; const UserName: String; const Msg: String; const FontName: String; FontColor: TColor; FontSize: Integer; const FontStyle: TFontStyles; rSocket: TWSocketClient); begin if Trim(UserName) = '' then begin Exit; end else begin SendLobbyCommand(LobbyID, 'š04œ' + LobbyID + 'œ' + UserName + 'œ' + Msg + 'œ' + FontName + 'œ' + IntToStr(FontColor) + 'œ' + IntToStr(FontSize) + 'œ' + FontStyletoStr(FontStyle) + 'œ'); end; end; any way to improve it?, I know it be hard reading code with no having all the correct codes so on also would you be able to supple me with a simple image stream demo for video I been looking all over for one and Never found it I would like to add video to my app one day ha. -Original Message- From: Simon Lewis Sent: Friday, December 05, 2014 6:53 PM To: TWSocket Archives Subject: Sending font styles and colors over network I know am flooding this news group with pointless questions but I really need to know, am building a chat system and I want to send basic text chat with font size/font color/font styles for each user am doing this via strings and sending to server and back to client but I noticed after a while and when more then a few users are typing the text chat becomes unstable and incorrect font styles / colors and sizes happen and only way to fix it is to re-login so am wondering what would be best way to send the information over network so it would be stable and reliable. Thanks -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending font styles and colors over network
Thanks for the Information am using TCP with custom process here code procedure TLobbyServer.SocketServerDataAvailable(Sender: TObject; ErrCode: Word); begin if ErrCode <> 0 then Exit; with Sender as TWSocketClient do begin RunCommand(ReceiveStr, Sender as TWSocketClient); end; end; procedure TLobbyServer.RunCommand(comdata: string; rSocket: TWSocketClient); var command: string; begin { INCOMING ENCODED DATA STRING } comdata := DecodeStr(comdata); { DECODE INCOMING DATA STRING } while DecodeCommand(comdata, command, dat) do begin case StrToIntDef(command, -1) of 00: begin LobbyChatMsgs(dat[0], dat[1], dat[2], dat[3], StrToInt(dat[4]), StrToInt(dat[5]), TFontStyles(Byte(StrToInt(dat[6]))), rSocket); end; end; end; procedure TLobbyServer.LobbyChatMsgs(const LobbyID: String; const UserName: String; const Msg: String; const FontName: String; FontColor: TColor; FontSize: Integer; const FontStyle: TFontStyles; rSocket: TWSocketClient); begin if Trim(UserName) = '' then begin Exit; end else begin SendLobbyCommand(LobbyID, 'š04œ' + LobbyID + 'œ' + UserName + 'œ' + Msg + 'œ' + FontName + 'œ' + IntToStr(FontColor) + 'œ' + IntToStr(FontSize) + 'œ' + FontStyletoStr(FontStyle) + 'œ'); end; end; any way to improve it?, I know it be hard reading code with no having all the correct codes so on also would you be able to supple me with a simple image stream demo for video I been looking all over for one and Never found it I would like to add video to my app one day ha. -Original Message- From: Simon Lewis Sent: Friday, December 05, 2014 6:53 PM To: TWSocket Archives Subject: Sending font styles and colors over network I know am flooding this news group with pointless questions but I really need to know, am building a chat system and I want to send basic text chat with font size/font color/font styles for each user am doing this via strings and sending to server and back to client but I noticed after a while and when more then a few users are typing the text chat becomes unstable and incorrect font styles / colors and sizes happen and only way to fix it is to re-login so am wondering what would be best way to send the information over network so it would be stable and reliable. Thanks -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending font styles and colors over network
> am building a chat system and I want to send basic text chat with font size/font color/font styles > for each user am doing this via strings and sending to server and back to client but I noticed > after a while and when more then a few users are typing the text chat becomes unstable > and incorrect font styles / colors and sizes happen and only way to fix it is to re-login so am > wondering what would be best way to send the information over network so it would be > stable and reliable. Are you using TCP or UDP ? UDP is by construction an unreliable protocol which is good for video or sound streaming where it is not very important to have some errors. TCP is by design a reliable protocol. It means you are sur to receive everything that has been sent, in the correct order without any error. If one of the conditions cannot be met, the you get noticed (First it starts to be slow because of transmit retries). TCP is reliable, but of course your code MUST check for all errors! It is easy to program without checking any error, but then you lose the reliability, not because of the internet protocol, but because of your code. Also, a common error with event driven asynchronous component such as ICS, is to call ProcessMessages (or any other derived method) without knowing exactly what it does. Incorrect use of ProcessMessages and the likes may result in lost events and then lost data. Another common error when using TCP is to forget that TCP is a stream oriented protocol. This means that although you receive everything sent, in the correct order and without error, several sent may be received as a single, larger chunk. Or a large data chunk sent at once may be read split into smaller chunks. This means you must at the application level handle this split/concatenation. It is exactly like writing to a file. The file reader cannot know how the file has been written. A text file can only be read line by line because of the CRLF which is used as line delimiter. My recommendation is to use TCP protocol and program everything asynchronously, using events. You may have a look at the chat client/server demo application in ICS. Btw: sending image, sound, text, color and font doesn't matters as far as transport is concerned. TCP nor UDP cares about what you transport. It is at the application level that it matters. It is your responsibility to design your application protocol so that the receiver knows what the sender has sent. -- francois.pie...@overbyte.be Embarcadero MVP http://www.overbyte.be http://francois-piette.blogspot.com -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Sending font styles and colors over network
> so am wondering what would be best way to send the information over > network so it would be stable and reliable. TCP/IP is a reliable network protocol, if data is being corrupted it must be your implementation of your private protocol. I would recommend you use the Magenta Systems IP Log Streaming Component for your chat system, it will hide all the TCP/IP stuff so you simply send a string and receive a string, that string being your own designed private protocol. http://www.magsys.co.uk/delphi/magics.asp There is an executable demo in the zip, you can run two copies, one as client, one as server, to see it all working. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] Sending font styles and colors over network
I know am flooding this news group with pointless questions but I really need to know, am building a chat system and I want to send basic text chat with font size/font color/font styles for each user am doing this via strings and sending to server and back to client but I noticed after a while and when more then a few users are typing the text chat becomes unstable and incorrect font styles / colors and sizes happen and only way to fix it is to re-login so am wondering what would be best way to send the information over network so it would be stable and reliable. Thanks -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be