|
-
Hi,
I am experimenting with a Perl xml socket server. This is all going well.
When a new user connects, the server automatically generates a usernumber which appears in the flash movie. What I am trying to do is replace this usernumber for it's actual username.
I wonder what the best way is to do this? Can a username be passed through from flash to the socket server at the time of connection? Or should there first be a connection > once connected send the userno associated with the new user back to him > send a message back to the server saying replace this username for the real user name?
Any ideas?
Thanks,
Raoul
-
Uhh...
Huh??
Either I think.
There really isn't any one way to do things - as long as it gets the job done.
I'd have Flash's onConnect event handler setup to send my user name...
myName="bobby";
myXML = new XMLSocket;
myXML.onConnect=handleConnect;
myXML.connect("blah.com", 12345);
function handleConnect (statusBoolean){
statusBoolean ? myXML.send(myName) : trace("Not connected");
}
-
Thanks Vaykent
I quess I was making things to complicated.
However I have problems invoking the onConnect eventhandler as the function handleConnect (in your example) is never executed.
Both sending messages and disconnecting are working fine.
I double checked on spelling mistakes.
Any ideas what is going wrong?
Raoul
-
Uhh...
Post the code you'e using, both client and server - maybe we can help...
-
thanks again for trying to help!
here is some of the code
Code:
flash movie:
server = "localhost";
port = 4445;
sock = new XMLSocket();
sock.connect(server, port);
sock.onConnect = onSockConnect;
sock.onClose = onSockClose;
sock.onXML = myOnXML;
function onSockConnect (success) {
if (success) {
msg = "Connected to "+server+" on port "+port;
sendXML("createUser",username);
} else {
msg = "There has been an error connecting to "+server+" on port "+port;
}
}
Perl:
#!/usr/bin/perl
# author [email protected]
use IO::Socket::INET;
use IO::Select;
# use URI::Escape; # you'll need this later i guess ...
$verb = 5; # verbosity for console messages
$main = new IO::Socket::INET (LocalHost => 'localhost',
LocalPort => 4445,
Listen => 5,
Proto => 'tcp',
Reuse => 1 ) || die $!;
$zero = chr(0);
$/ = $zero;
$\ = $zero;
$| = 1;
# Initialise IO::Select ------------------------------------------------
$handles = new IO::Select();
$handles->add($main);
print "Starting listening cycle\n" if ($verb > 1);
LISTEN: while (1) {
($pending) = IO::Select->select($handles, undef, undef, 60);
foreach $sock (@$pending) {
if ($sock == $main) {
$num++;
print "Got new connection: $num from ".$sock->sockhost()."\n" if ($verb > 2);
my $newsock = $sock->accept();
$newsock->autoflush();
$number{$newsock} = $num;
$handles->add($newsock);
} else {
my $buf = <$sock>;
if ($buf) {
print "Existing socket $number{$sock} is pending: " if ($verb > 3);
chomp $buf;
print "$buf\n" if ($verb > 3);
($data) = $buf =~ /data="(.*?)"/;
print $sock qq|<response data="You said '$data'" />|;
} else {
print "Socket $number{$sock} is gone.\n" if ($verb > 2);
$handles->remove($sock);
}
}
}
}
The perl script above is the original (which had the same problem).
To work around the problem I am having I simply added this line:
Code:
print $newsock qq|[newUser data="not important" /]|;
(where '[' should be '<' and ']' should be '>' , to make things visible here on the board)
at the end of the if-statement: if ($sock == $main)
which arrives in flash as an onXML eventhandler, then the flash movie automatically sends the username.
This is working fine, nevertheless it would be helpful to know why the onConnect event handler is not invoked?
regards,
Raoul
-
Uhm...
I'm at work right now - so I can't spend too much time looking at your code - but a word of warning - do't set the EOL character as a global variable... I used to do that, and I've run into trouble.
I code my Socket Servers in Ruby now - so I'm not sure how erl would handle this.. but in Ruby you can append the EOL char with the gets method...
# s is the server socket object...
s.gets("\0") # This will read in from Flash
s.puts "hello!\0" # This will write to Flash...
So you might want to look into something like that. It could be a pain if you don't centralize the method to 'read/write' the socket...
Anyway... You might want to check out a server I wrote in Perl a while ago (I wouldn't do it that way now...)
http://www.tupps.com/flash/faq/xml.html
-
Yes, I have looked at your perl server as well and the ruby server underneath it. Unfortunately, I don't know how to program in ruby.
The script as it is now, seems to work fine. What kind of problems can I expect with EOL chr set the way it is now?
Raoul
-
Uhm...
Try writing to a log file, then open it in notepad.
Try reading in a 'bad-word-filter-list'... read it in line by line.
Things like this. If you never need to communicate with anything other than Flash - great! Otherwise it might not be a good idea to et the global EOL char.
-
ahh, yes, didn't think of that.
Good to remember that in case I get to the point that things like you mentioned need to be implemented.
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|