New to oF, but lots of processing experience. I’m having an issue with the ofxTCPServer example (networkTcpServerExample) where I can’t get it to receive any data sent from a connected client.
So basically, I run the server at port 10002, and have a client (tried a bunch of different stuff… Processing client via localhost, iPhone via ip, etc.) connect to the server. Check. The example, as it should, spits out a “client connected to server from ip x at port y.” However, when I try to actually send messages over the connection, nothing gets received. Am I doing something wrong? Some trick involved? I’ve tried my client connections w/ processing and python to verify it’s not a client issue.
the tcp client/server classes use a trick to send/receive complete messages. since tcp is a stream oriented protocol you cannot know when the message ends so every time you send something with:
bool send(string message);
it appends a [/TCP]\0 at then end of the message as a terminator to detect where a message ends.
string receive(int clientID);
in the server expects that ending and if it doesn’t get it it doesn’t return anything. it’s explained in the comment of that method in ofxTCPServer.h:
//get the message as a string
//this will only work with messages coming via
//send() and sendToAll()
//or from messages terminating with the STR_END_MSG
//which by default is [/TCP]
//eg: if you want to send "Hello World" from other
//software and want to receive it as a string
//sender should send "Hello World[/TCP]"
you can append that terminaror in your message or use:
int receiveRawBytes(int clientID, char * receiveBytes, int numBytes);
to receive anything.
awesome. thanks very much.
Hi all ,
i am uping this topic, after having some trouble …
i understood the problem, but how do i add [/TCP] to a received message when it is google.com answering to my request ?
instead of receive, just use receiveRawBytes. or if it’s an http service, better use ofxHttpUtils:
thanks arturo i’ll try http service. I got some trouble with the receiveraw(). ( to get full answer )
thanks twice it solved everything