Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-20-2007, 07:45 PM   PM User | #1
doc
New to the CF scene

 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
doc is an unknown quantity at this point
flash xml client socket will not connect to php socket server

Hi
I am trying to connect a Flash client socket (XML) to a php socket server (using Flash 8 and php 5).
My php socket server responds correctly when I connect to it with a php client socket but fails when I try to connect with the flash xml client socket.

Both codes are included below - they are both in the same folder on the web site and I am only trying to get them to connect.

Cheers

doc

THE PHP SOCKET SERVER (run on browser for the moment - daemon later when sorted!)
<?php
// set some variables
$host = "my ip address";
$port = 1234;
// don't timeout!
set_time_limit(0);
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");
// bind socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
// start listening for connections
$result = socket_listen($socket, 5) or die("Could not set up socketlistener\n");
// accept incoming connections
// spawn another socket to handle communication
$spawn = socket_accept($socket) or die("Could not accept incomingconnection\n");
// read client input
$input = socket_read($spawn, 1024) or die("Could not read input\n");
$output = "Hello"."\0";
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
// close sockets
socket_close($spawn);
socket_close($socket);
?>

THE FLASH CLIENT SERVER (this is a one frame swf run on a simple web page)
mySocket = new XMLSocket();

mySocket.onConnect = function(success) {
if (success) {msgArea.htmlText += "<b>Server connection established!</b>";} else {
msgArea.htmlText += "<b>Server connection failed!</b>";}
}

mySocket.onClose = function() {
msgArea.htmlText += "<b>Server connection lost</b>";
}

mySocket.prototype.onData = function(msg) {
msgArea.htmlText += msg;
}

mySocket.connect("my ip address", 1234);

Last edited by doc; 03-21-2007 at 01:57 PM..
doc is offline   Reply With Quote
Old 03-22-2007, 05:25 PM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,890
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
not a clue about xml and flash but it seems to me that flash would be expecting XML output ? 'Hello' is badly formed so perhaps flash is rejecting it ?
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 03-22-2007, 06:36 PM   PM User | #3
doc
New to the CF scene

 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
doc is an unknown quantity at this point
Thanks for the reply.
XML requires that any message ends with "\0" although other things may be accepted. Once 'listen' has accepted the incoming caller the connection is made and the rest doesn't matter. For the moment I am just trying to get the connection to be made with flash as it does with php. I've done a fair bit of this stuff but quite a few years ago and things have changed a bit so it's very frustrating to not be able to do it (apart from needing it urgently for a work project!)
Thanks again - doc
doc is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:27 AM.


Advertisement
Log in to turn off these ads.