Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1792
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 Wink

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 Wink 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
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Using U++ without UppIDE
Next Topic: [ASK] IBM DB2 Connector
Goto Forum:
  


Current Time: Sun Aug 24 19:17:56 CEST 2025

Total time taken to generate the page: 0.05151 seconds