Hi, i am trying to develop a socket server with TcpListener in C#.
it will accept XMLSocket from flash clients and eventually im trying to make a simple multiplayer enviornment.
i’ve so far created a server.exe from c# that simply listens and accept the tcp connection, announce(only within the program yet, not to all clients) if the client is connected and announce when the client leaves.
it is working fine from flash IDE (when you ctrl+enter to test) but
it is not working from the published swf file.
i don’t know much about server administration so i dont know if im doign it right but ive created a crossdomain.xml and save it to root of the localhost (im using apache installed on my machine for local testing);
Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://localhost/socket.swf cannot load data from 127.0.0.1:8888.
at socket_fla::MainTimeline/frame1()
this is the error mesasge that i get from flash player 10, after its trying to communicate with the server(about 10sec, it shows).
System.NullReferenceException: Object reference not set to instance of an Object.
this is the error i get from the C# server. from catch{}.
//Flash File
//Security.loadPolicyFile("crossdomain.xml");
var socket:XMLSocket = new XMLSocket();
socket.connect("127.0.0.1",8888);
socket.addEventListener(Event.CONNECT, connected);
socket.addEventListener(DataEvent.DATA, getMsg);
function connected(e:Event):void
{
var xml:XML = <xml><id>won029301</id><name>won</name></xml>;
socket.send(xml);
}
function getMsg(e:DataEvent):void
{
}
// C# Server
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Xml;
using System.Collections;
using System.Threading;
namespace SocketFlashServer
{
class Program
{
static void Main()
{
TcpListener server = new TcpListener(IPAddress.Loopback, 8888);
server.Start();
Console.WriteLine("Server: Server Started...");
while (true)
{
Console.WriteLine("Server: Waiting for Client...");
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Server: Client Accepted...");
NetworkStream stream = client.GetStream();
Byte[] byteArray = new Byte[10025];
stream.Read(byteArray, 0, (int)client.ReceiveBufferSize);
String data = Encoding.UTF8.GetString(byteArray);
XmlDocument xml = new XmlDocument();
xml.LoadXml(data);
try
{
String clientName = xml.GetElementsByTagName("name")[0].InnerText;
String clientId = xml.GetElementsByTagName("id")[0].InnerText;
Console.WriteLine("Server: {0} (id:{1}) joined the server...", clientName, clientId);
new HandleClient(client, clientId, clientName);
}
catch (Exception ex)
{
Console.WriteLine("Server: Error - {0}", ex.ToString());
}
}
}
}
class HandleClient
{
TcpClient client;
String id;
String name;
public HandleClient(TcpClient _client, String _clientId, String _clientName)
{
this.client = _client;
this.id = _clientId;
this.name = _clientName;
Thread session = new Thread(sessionStart);
session.Start();
}
private void sessionStart()
{
Boolean isConnected = client.Connected;
while (isConnected)
{
isConnected = client.Client.Poll(01, SelectMode.SelectRead) ? false : true;
}
sessionEnd();
}
private void sessionEnd()
{
client.Close();
Console.WriteLine("Server: {0} (id:{1}) has left the server...", name, id);
}
}
}
//crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="ALL"/>
<allow-access-from domain="*"/>
</cross-domain-policy>
Please help, i do not know what to do now… T.T