Flash Binary TCP Socket Connection


I have been trying to get a TCP socket connection working from Flash to OF. I have successfully connected my flash client to a server that I wrote in Processing and could send/receive fine.

I then tried the NetworkTCPServer example from OF, and I could connect my flash client to it and receive messages from the server, but when I send a message to the server from flash, it doesn’t seem to receive it. I’ve checked the forum for help, and there was mention of this problem, but no real solution was presented.

Does anyone have any ideas what the problem might be?



This is a shot in the dark but maybe this could point you in the right direction : http://www.onflex.org/ted/2006/03/st-pa-…-server.php

  • this comment refers to Python but may be applicable to OF?

Thanks, xsvdo but as I said, I’d already got it working in Processing, so I think it is an issue with the way the of network addon is working rather than the way that I am trying to connect. I have a perl policy server set up to send the policy to flash and I am trying to connect with my flash client to the OF server.

I can connect to the server, and flash can receive messages from the server, but if I send a message from Flash, the server doesn’t seem to get it :confused:

there is some info:


hope that helps !!

Hi zach,

I’d already checked those threads-

In this one http://www.openframeworks.cc/forum/view-…-=flash+tcp gabon mentions that he had the problem that I have (i.e. the server not getting anything from flash) but he doesn’t really present a solution for his problem.

I have tried using the server example as-is (along with a policy server), and I’m sending an UTF-8 encoded string from flash, but nothing shows up on the server (which is strange, as the two OF server examples can talk to each other, and my flash client talks to my server in Processing.org). I guess I’m gonna have to do some debugging tonight. Something fishy is going on…

EDIT: Weird… it can’t receive messages from a client that I wrote in Processing either… (I outputted the size of received strings and it always says 0)

Hey guys,

I’ve ran into a project that has lead me to use Flash to C++ socketserver communication. I’m resurrecting this post because I haven’t found the solution in any of the threads regarding sending information from Flash to the OF tcp Server [from Addons example]. Sending data from C++ compiled server to Flash works GREAT. However, like CongoZombie and Gabon, I haven’t been able to send Flash data back to the Server.

Here is a link where I got a flash working great with a java app

Attached is the Flash example that I used. Below are small modifications done to the networkTcpServerExample addon to send some data to Flash. Replace the code into the testApp.cpp example. - When you are running the app press ‘s’ so that you can see the swf file receiving string info from c++.

Download flash example here:

Hopefully somebody can enlighten my path!
Note: I’m using of_preRelease_v0061_osxSL_FAT and ActionScript 3

Insert a boolean in the testApp.h file:
bool bGate;

#include "testApp.h"  
void testApp::setup(){  
	//we run at 60 fps!  
	//load our type  
	mono.loadFont("type/mono.ttf", 9);  
	monosm.loadFont("type/mono.ttf", 8);  
	//setup the server to listen on 11999  
	bGate = true;  
void testApp::update(){  
	ofBackground(20, 20, 20);  
	//for each client lets send them a message letting them know what port they are connected on  
	for(int i = 0; i < TCP.getNumClients(); i++){  
		if (bGate == true) { // A boolean is included so that TCP.send() is sent only once.  
			TCP.send(i, "hello client - you are connected on port - "+ ofToString(TCP.getClientPort(i)) );  
			bGate = false;  
void testApp::draw(){  
	mono.drawString("TCP SERVER Example \n\nconnect on port: "+ofToString(TCP.getPort()), 10, 20);  
	ofRect(10, 60, ofGetWidth()-24, ofGetHeight() - 65 - 15);  
	//for each connected client lets get the data being sent and lets print it to the screen  
	for(int i = 0; i < TCP.getNumClients(); i++){  
		//give each client its own color  
		ofSetColor(255 - i*30, 255 - i * 20, 100 + i*40);  
		//calculate where to draw the text  
		int xPos = 15;  
		int yPos = 80 + (12 * i * 4);  
		//get the ip and port of the client  
		string port = ofToString( TCP.getClientPort(i) );  
		string ip   = TCP.getClientIP(i);  
		string info = "client "+ofToString(i)+" -connected from "+ip+" on port: "+port;  
		//if we don't have a string allocated yet  
		//lets create one  
		if(i >= storeText.size() ){  
			storeText.push_back( string() );  
		//we only want to update the text we have recieved there is data  
		string str = TCP.receive(i);  
		if(str.length() > 0){  
			storeText[i] = str;  
		//draw the info text and the received text bellow it  
		monosm.drawString(info, xPos, yPos);  
		monosm.drawString(storeText[i], 25, yPos + 20);  
void testApp::keyPressed(int key){  
	if (key == 's' ){  
		for(int i = 0; i < TCP.getNumClients(); i++){  
			cout << "str: " << storeText[i] << endl;  
			TCP.send(i, "hello client. This is socket server in c++ - "+ storeText[i]);  
	} // Press 's' key to send this string back to Flash.  

hi donny

OF send method adds a [/TCP] terminator at the end of the message to be able to detect the end of it. flash does the same but adds a \0 at the end.

the same happens in the other direction, in flash when you receive a message it should end in \0 or it will never detect the end. indeed OF also adds a \0 at the end so there’s no problem with flash and you surely are seeing the [/TCP] at the end in the messages received in flash.

what you need to do is just add [/TCP] at the end of you flash messages and OF will be happy : )


Adding [/TCP] was the solution! Now I’ve learned something from both C++ and AS 3 side. Zach had actually suggested that but the thread was old and the termination I guess used to be /ofTCP instead of [/TCP] in older versions of OF.

Thanks a lot! :smiley: