I'm creating a client-server game. My client is a flex based game, and my server is erlang server.
At the beginning, when I test directly my flex client in flash player, I can establish a connection easily to my erlang server through socket connection. And both can exchange data with no problem.
The problem rise when I deploy my flex app at Apache http server, and running it using a browser by calling http://localhost/ ... my flex socket sends message requesting for a crossdomain policy to my erlang server.
So I create an xml message that represent a crossdomain policy, and send it back to my flex app as a response for that request.
Yet still I can't establish any permanent socket connection between my flex client and my erlang server. I know this because I add listener on my flex socket that will modify its internal state to CONNECTED, if a connection between client-server has established.
I haven't experienced the problem but maybe this would help.
The default policy file is named
crossdomain.xml and resides at the
root directory of the server that is
serving the data...
You can use the loadPolicyFile() method to access a nondefault policy file.
http://livedocs.adobe.com/flex/3/html/help.html?content=deployingoverview_12.html
A policy file served by an XMLSocket
server has the same syntax as any
other policy file, except that it must
also specify the ports to which access
is granted. When a policy file comes
from a port lower than 1024, it can
grant access to any ports; when a
policy file comes from port 1024 or
higher, it can grant access only to
other ports 1024 and higher.
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00005403.html
The flashplayer restricts your socket usage in several ways. One you already found out :) The other is to specify whether you use the network or not. There is a networking mode and a file system mode (access to the filesystem). You can't have both.
So you should try to compile it with this:
-use-network=true
And yes I know it's a PITA doing socket programming with flash. You should implement every OnErrorXYZ method and print as much information as possible. Using wireshark or a different network sniffer is also a good idea.
Related
I am working on a client/server program with one server (not behind NAT) and many clients that are using NAT. I need the server to be able to transfer files to the clients every so often, thus the server must be able to initiate TCP traffic when needed. I have already figured out how to do this with UDP by caching the clients' IPEndPoints and using them later.
Can anyone recommend some sample code or a project (with source) they have seen that can do this? There are lots of Chat or IM projects out there to learn from, but they generally use only UDP across NAT or only work on LANs without NAT being used. C++/C#/VB source with a solution would help a lot. Thanks.
Your best options:
Clients polls periodically to discover if new files are available. Simplest option. This may or may not scale depending on how many clients and how often they would need to poll.
All clients keep a persistent TCP connection to the server. Server sends files to a specific client when ready. Avoids the polling overhead of #1, but might have issues if the number of clients reaches into the thousands if you haven't designed your service to scale for the C10K problem.
Clients connect to a notification server which is designed to handle many clients simultaneously connected. Client sends its notification server parameters to file transfer service and disconnects. When file server has a new file available, server sends notification through notification service to tell client to connect back for an awaiting file. Client disconnects from file server after file transfer is done.
I want my client program to communicate with a server without making the user add an exception to Windows Firewall in elevated mode. Is there a way to do this? HTTP? For instance, uTorrent and Google Chrome can both be installed by a regular (non-admin) user, and both programs network quite extensively - how do they do this? Am I missing something about how the firewall and/or ports works?
Yes there is a way. Assuming that your client program is the one running on the users machine and that your client program is the one initiating communication with the server then your client program generally would not need to require end user to open any exceptions in the windows firewall as long as you stick to using http over port 80. Http on port 80 is generally open for outbound traffic (initiated by the client) and therefor you could build your communication (and if needed your own protocol) on top of the http protocol. This is the typical scenario for webserver and webbrowsers (clients).
If you need the server to initiate the communication it becomes more complex and a lot of different approaches could be used. Choice of communication channels and structure should depend on factors like whether you would want to communicate to one client at a time or many (broadcast/multicast), do you need encryption, what are your needs for speed (throughput and latency), what kind of system are you trying to build and so on.
Many webapplications achieve an effect of a server initiated communication by using special techniques called polling, long polls, comet, websockets and so on. these work through http on top of tcp/ip on port 80. Other systems employs subscription mechanisms to be able to get notified through a third part if something new has happened. If you need server initiated communications please let me now and i will try to give a better explanation on the options.
i've been searching and trying for weeks now to find a solution to my issue that I can understand and easily implement but I had no joy. So i would be very grateful if someone could put me out of my misery.
I'm building an iphone app similar in functionality to apps like "Air Video" and "Air Playit". The app should communicate with a server running on a remote host. This server should be able to execute a command sent by the iphone to encode a video and stream it over http.
In my case, my iphone app sends commands to be executed on a remote host. the remote host is running a python socket server listening for example on port 3333.
On the iphone, i'm simply using
"CFStreamCreatePairWithSocketToHost", "CFWriteStreamOpen" and
"CFReadStreamOpen"
to connect, write and read data.
My remote host, successfully intercepts the commands and starts the encoding.
To serve the contents, I'm having to run a separate http server (i'm using Python simpleHTTPServer) which is listening on another port.
What I would like to do is use the same port for both system commands and http requests.
The apps I've mentioned above seem to do it that way and I've noticed they have their own build-in web server.
I'm sure I'm missing something but please bear with me this is my first attempt at building an app.
Encode your system commands into special HTTP requests. Decide which thing to do (execute command or serve the contents) based on HTTP request, not on the incoming port. If you need to use separate http servers (like you told), consider having a layer that receives everything from the devices and dispatches to other servers (or ports) based on the request.
I am using a Socket (not xmlSocket) connection between flex applications and the server pushing messages.
Now, when I connect from the local machine to the server everything is working file and running, connection is succesful and I get data back and forth.
When I upload the application (flex) to the server and run it from there, I get a security sandBox violation message.
Note:
1. I do have a crossdomain file with * wildcard both on port and on domain.
2. I created a Securiy.allowDomain("*") as well.
Another thing.
I also created another listener on that same server, listening to connections for port 843 (default) and this service just waited for a connection send policy file to the client and that's it.
That did not solve the problem as well...
That's next?
What should I do to fix the problem?
Appreciate your help.
Avi
The fix for this issue was a dedicated policy file serving server.
I implemented a socket listening to the dedicated port where flex is looking for policy file, once I got a connection and a request I answered right back with the appropriate policy file.
This solved the problem for all users and is working very well for me.
Thanks
did you try Security.loadPolicyFile? Does your server on port ever actually 843 receive policy file requests (that's a tiny XML sent to request the crossdomain policy file)? Does your actual server ever receive policy file requests? What traffic do you get on your server?
greetz
back2dos
.NET
Add crossdomain.xml to your Web server root directory, for example,
C:\inetpub\wwwroot.
Java
Add crossdomain.xml to \ArcGIS\java\web_output, for example,
C:\Program Files\ArcGIS\java\web_output.
http://resources.esri.com/help/9.3/arcgisserver/apis/flex/help/content/deploy_application.htm
I want to open a connection back to the server using Flex so I can stream chat messages to the Flex front-end. How do I do this and does Flex enforce any same-origin restrictions on ports or subdomains?
You'll have to use a messaging server software and then use the Producer and Consumer classes in the Flex framework to send and receive messages.
What you need depends on what server you are running on. If you are on a Java stack, you can use BlazeDS and ActiveMQ.
If you are streaming/consuming from and to different domains, you'll need to setup a crossdomain file that allows the inter-domain communication.