1, modify EchoServer :: onMessage (), to achieve invert case
- Modify EchoServer :: onMessage ()
After receiving msg conversion
for(unsigned int i = 0;i<msg.size();++i){
if(msg[i] >= 'a' && msg[i] <= 'z'){
msg[i] = char(msg[i] - 'a' + 'A');
continue;}
else if(msg[i] >= 'A' && msg[i] <= 'Z'){
msg[i] = char(msg[i] - 'A' + 'a');
continue;}
}
The source code shown in FIG.
- Run code validation
run echo in a terminal program.
# cd bin
# ./echo
In a further run the command terminal
# telnet localhost 2007
2, modify EchoServer :: onMessage (), to achieve ROT13 encryption
- ROT algorithm first understand the principles http://en.wikipedia.org/wiki/ROT13
- Modify EchoServer :: onMessage ()
for(unsigned int i = 0;i<msg.size();++i){
if((msg[i] >= 'a' && msg[i] <= 'm') || (msg[i] >= 'A' && msg[i] <= 'M')){
msg[i] = char(msg[i] + 13);
continue;}
else if((msg[i] >= 'm' && msg[i] <= 'z') || (msg[i] >= 'M' && msg[i] <= 'Z')){
msg[i] = char(msg[i] - 13);
continue;}
- Run code validation
run echo in a terminal program.
# cd bin
# ./echo
In a further run the command terminal
# telnet localhost 2007