•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 429,970 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,598 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 6322 | Replies: 4
![]() |
•
•
Join Date: Mar 2007
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
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>";
}
XMLSocket.prototype.onData = function(msg) {
msgArea.htmlText += msg;
}
mySocket.connect("my ip address", 1234);
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>";
}
XMLSocket.prototype.onData = function(msg) {
msgArea.htmlText += msg;
}
mySocket.connect("my ip address", 1234);
Last edited by eldoc : Mar 20th, 2007 at 12:18 pm.
•
•
Join Date: Sep 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Hey. I have the same problem, exactly. I figured that the php client can connect because it is on the same folder and server (trinitrol.com) as the php server. However, my flash client is on another computer.
The php server is bound on 127.0.0.1 (localhost), and so is the php client, so it works. The flash client tries connecting to trinitrol.com (or 72.47.196.123) and it doesn't work.
I yet to find a solution which I think is binding the server to the public host 72.47.196.123 which still doesn't work.
If you have MSN/Windows Live Messenger, talk to me at (neo at tranysiss.com) or e-mail me at (celeroncyto at gmail.com). Let me know if you find a solution.
Cheers.
The php server is bound on 127.0.0.1 (localhost), and so is the php client, so it works. The flash client tries connecting to trinitrol.com (or 72.47.196.123) and it doesn't work.
I yet to find a solution which I think is binding the server to the public host 72.47.196.123 which still doesn't work.
If you have MSN/Windows Live Messenger, talk to me at (neo at tranysiss.com) or e-mail me at (celeroncyto at gmail.com). Let me know if you find a solution.
Cheers.
•
•
Join Date: Sep 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
i saw, do you use socket_read on server side (some time it doesn't work for flash)
your code:
#$input = socket_read($spawn, 1024) or die("Could not read input\n");
$output = "Hello"."\0";
#
try replace the code to:
$bytes = socket_recv($socket, $buffer, 2048, 0);
if($byte != 0)
{
echo $buffer;
}
//on the client side remember ( flash)
to use "\n" on the end of the message you send.
i hope it will help!
your code:
#$input = socket_read($spawn, 1024) or die("Could not read input\n");
$output = "Hello"."\0";
#
try replace the code to:
$bytes = socket_recv($socket, $buffer, 2048, 0);
if($byte != 0)
{
echo $buffer;
}
//on the client side remember ( flash)
to use "\n" on the end of the message you send.
i hope it will help!
•
•
•
•
Hey. I have the same problem, exactly. I figured that the php client can connect because it is on the same folder and server (trinitrol.com) as the php server. However, my flash client is on another computer.
The php server is bound on 127.0.0.1 (localhost), and so is the php client, so it works. The flash client tries connecting to trinitrol.com (or 72.47.196.123) and it doesn't work.
I yet to find a solution which I think is binding the server to the public host 72.47.196.123 which still doesn't work.
If you have MSN/Windows Live Messenger, talk to me at (neo at tranysiss.com) or e-mail me at (celeroncyto at gmail.com). Let me know if you find a solution.
Cheers.
I have the same problem too, i using delphi as the server, it work smoothly as individual application but it doesn't work when i run it in a web browser, i already add global security option for this file. Adobe.com mention something about cross domain file and "Flash Player security features" . Somebody can help me ???
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
api architecture asp backup blog blogger blogging code competition crash daniweb database dell development dom enterprise feed flash flash gdata google html internet laptop linux mail memory microsoft mmorpg news novell open php programming qmail reader rss sandisk security server smtp software source standards w3c weather web windows xml xoap
- Help Needed (Networking Hardware Configuration)
- What will a flash xml socket connect to - please help - insanity is near (PHP)
- I Can'f Find a Hosting Company that allows me to do socket programming! (PHP)
- SMS Message With PHP/MYSQL (PHP)
- Cannot connect to server (MySQL)
- how php is related to server scripting? (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP problem
- Next Thread: PDF creation: Wrap text on Table with Fpdf


Linear Mode