Solved

TCP socket connection Flex 3 - funny square returned.

Posted on 2009-05-07
2
3,891 Views
Last Modified: 2012-05-06
i'm busy fiddling around with flex as I've decided to do my next project in flex - just for fun.
i found some code on how to connect to a TCP socket .

it returns values like this
<?xml version="1.0"?>

<Msg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <ACK fromSystem="blah" msgType="Connect" />

</Msg> <--- it has a square at the end of it. you can't really see it here
anyone have any idea why its doing that and what i have to do to get rid of it?


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
	<![CDATA[
		private var socket:Socket = new Socket();
 
		private function load():void{
			socket.connect('127.0.0.1', 8080);
        	socket.addEventListener(Event.CONNECT, connectedHandler);
			socket.addEventListener(ProgressEvent.SOCKET_DATA, inputDataHandler);
		}
		
	    private function inputDataHandler(event:ProgressEvent):void {
			var bytesLoaded:int = socket.bytesAvailable;
			var str:String = socket.readUTFBytes(socket.bytesAvailable);
			myT.text+=str;
	    }
 
    	private function connectedHandler(event:Event):void {
        	socket.writeUTFBytes("GET /sockets.html HTTP/1.0\n\n");
        	socket.flush();
	    }
	]]>
	</mx:Script>	
 
	<mx:Button click="load()" label="load"/>
	<mx:TextArea x="10" y="30" width="680" height="395" id="myT"/>
</mx:Application>

Open in new window

sample.bmp
0
Comment
Question by:blue-genie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 24326278
Hi blue-genie,

Even if the Socket conneciton is a virtually permanent connection, it is still based on the packets of the TCP stack. It would be very imperformant to add every byte to a 50k packet. This is why flex buffers the data that will be output. In order to tell Flex to send the data, a "\0" termination-byte is added to the message. This tells Flex that the current message should be flushed.

On the server side there is another problem: In case of Xml this is no problem at all, but you could imagine sending raw byte data. How does the server know when a message is finished? This is where the "\0" byte comes into action. This byte is the one making your "readLine" return.

Is the byte really doing harm? If yes, you could just drop it or write a custom InputStream that drops it for you.
0
 
LVL 39

Author Closing Comment

by:blue-genie
ID: 31578980
so that's normal? hmm okay.
thanks for that information.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Closing FLash Privacy/Video Panel 2 870
Adobe Air with Flex on ios 2 1,129
looking for noob/pro flash game developers to grow with 4 663
ComboBox ItemRenderer inside Datagrid 2 1,085
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question