Home » Community » Newbie corner » Socket - send multiple lines
Re: Socket - send multiple lines [message #29727 is a reply to message #29710] |
Wed, 10 November 2010 22:10   |
|
Hi Neil,
Simple trick I used in similar situation:String Escape(const char* q) {
String esc;
for(;*q;q++){
if(*q=='\\') esc.Cat("\\\\");
else if(*q=='\n') esc.Cat("\\n");
else esc.Cat(*q);
}
return esc;
}
String Unescape(const char* q){
String unesc;
for(;*q;q++) if(*q == '\\'){
if(*(q+1)=='n'){unesc.Cat('\n');q++;}
else if(*(q+1)=='\\'){unesc.Cat('\\');q++;}
else unesc.Cat(*q);
}else unesc.Cat(*q);
return unesc;
}
//Example usage:
String manylines="line 1\nline 2\nline 3\n";
String singleline=Escape(manylines); //this can be send using your single line code without major changes
//on the other side just call:
String str=Unescape(s.ReadUntil('\n'));
Note that this is only a workaround and requires you can change source of both client and server, but for me at that time it was the quickest solution 
Regarding the question in your other post: You can use any C++ in U++ without problems. Note though, that using C++ sockets directly, you will loose the multiplatform behavior. Also, usually the stuff you need is already available in U++ even if you don't see it at first I am not familiar enough with the socket stuff to really help you, but hopefully someone else here will be able to point you in the right direction...
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Sun Aug 24 19:17:56 CEST 2025
Total time taken to generate the page: 0.05151 seconds
|