Best convention of tcp-messaging - network-programming

I'am using this message convetion : %total_msg_length%|%msg_body% to recieve string data over tcp-sockets (python/pyqt). Is this is the good convetion, or should i try something else?

It's not uncommon.
Another way than having a separator (like your |) would be to have the message length be fixed size, like always 4 or 8 characters. Then you can read 4 (or 8 or what you choose) to get the message size. The problem with this is that you have to make at least two calls to recv: One for the length and one for the body.

Related

How to use same custom text string for multiple Grails constraint messages in .properties files to avoid duplication

We have a number of constraints for the same object that should result in the same error message to the user, but cannot see a way of sharing the text. This leads to smelly duplication. For example:
myInternationalizedProps_en.properties
myClassName.propertyName.minSize.notmet = your entry must be between 6 and 10 characters
myClassName.propertyName.maxSize.notmet = your entry must be between 6 and 10 characters
Any way to collapse these into a single entry? Using Grails 2.3.x
The short answer is "no". There's no way to use a message for different types of constraints. However for the particular case shown in your example, you could replace the minSize and maxSize constraints (and messages) with a single size constraint (and message).

iOS Twitter post issue - number of characters

As I know the max length of characters for twitter post is 117. When I post plain text. it's no problem. But when I add a text for hyper link, it will cause problem when I post 117 characters (I can reduce the total length in order to post successfully). Why is like that?
Plain text:
Text with url inside:(this will cause problem even there are 3 characters remains. But if I keep reducing the characters. For example, 10 characters left, then I can post successfully)
Error:
I think the Twitter count algorithm is different from iOS. Any idea? Thanks
I figured it out finally. My conclusion:
The maximum length of twitter text is 140 in web, 117 in iOS if there is no url inside.
The length of each url is 23 no matter original length of the url is. So you have to calculate the maximum length of text allowed by yourself.
Refer to https://github.com/twitter/twitter-text for details although the max length in ObjC is wrong.

What should I do with emails using charset ansi_x3.110-1983?

My application is parsing incoming emails. I try to parse them as best as possible but every now and then I get one with puzzling content. This time is an email that looks to be in ASCII but the specified charset is: ansi_x3.110-1983.
My application handles it correctly by defaulting to ASCII, but it throws a warning which I'd like to stop receiving, so my question is: what is ansi_x3.110-1983 and what should I do with it?
According to this page on the IANA's site, ANSI_X3.110-1983 is also known as:
iso-ir-99
CSA_T500-1983
NAPLPS
csISO99NAPLPS
Of those, only the name NAPLPS seems interesting or informative. If you can, consider getting in touch with the people sending those mails. If they're really using Prodigy in this day and age, I'd be amazed.
The IANA site also has a pointer to RFC 1345, which contains a description of the bytes and the characters that they map to. Compared to ISO-8859-1, the control characters are the same, as are most of the punctuation, all of the numbers and letters, and most of the remaining characters in the first 7 bits.
You could possibly use the guide in the RFC to write a tool to map the characters over, if someone hasn't written a tool for it already. To be honest, it may be easier to simply ignore the whines about the weird character set given that the character mapping is close enough to what is expected anyway...

Character #\u009C cannot be represented in the character set CHARSET:CP1252 - how to fix it

As already pointed out in the topic, I got the following error:
Character #\u009C cannot be represented in the character set CHARSET:CP1252
trying to print out a string given back by drakma:http-request, as far as I understand the error-code the problem is that the windows-encoding (CP1252) does not support this character.
Therefore to be able to process it, I might/must convert the whole string.
My question is what package/library does support converting strings to certain character-sets efficiently?
An alike question is this one, but just ignoring the error would not help in my case.
Drakma already does the job of "converting strings": after all, when it reads from some random webserver, it just gets a stream of bytes. It then has to convert that to a lisp string. You probably want to bind *drakma-default-external-format* to something else, although I can't remember off-hand what the allowable values are. Maybe something like :utf-8?

Blackberry scrambled device ID in 8 characters unique

I need to scramble Device IDs on the Blackberry for privacy matter.
When I call the function DeviceInfo.getDeviceId() I got a 9 characters number. After convert it in Hexa, I got the real PIN number for the device (or device ID depends how you call that) on 8 characters.
Like I said, for privacy matter I can't store the PIN as is in my database. So I would like to scramble the ID to a unique one, still in 8 characters. If I do MD5 or other encryption, I always got an number containing more than 8 characters.
Do you know a way to get a unique 8 characters string from the Device ID?
Thank you.
You can use a short block cipher to obsfucate the message. Look at the CBC-MAC mode of operation.
As the output you want is actually only 4 bytes long, you could even use a CRC, such as CRC32.
Note that you would need a "perfect hash" to not have an overlap - neither short key CBC-MAC or CRC32 will give you a perfect hash. I would strongly suggest using a longer hash function.

Resources