Hi I am trying to send a simple HTTP message from Flex to C# server, but it seems that I am getting tow calls, first is the real one and the second is an empty one.
Why is that and how can I handle it?
This is my C# code:
TcpListener listener = new TcpListener(IPAddress.Any, 9400);
listener.Start();
Console.WriteLine("Server started");
Socket client;
while (true)
{
client = listener.AcceptSocket();
// client.Available is an expensive call so it's just for testing
Console.WriteLine("Client accepted " + client.Connected + " " + client.Available);
SocketHandler handler = new SocketHandler();
ThreadPool.QueueUserWorkItem(handler.handleSocket, client);
}
this is the SocketHandler:
public void handleSocket(object socketObjeck)
{
try
{
socket = (Socket)socketObjeck;
byte[] buffer = new byte[1024];
SocketSettings.setSocket(socket);
//blocker...
try
{
socket.Receive(buffer);
}
catch (Exception e)
{
Console.WriteLine("Error\nFaild reading from socket\n" + e.Message);
socket.Close();
return;
}
parseData(buffer);
socket.Close(3);
}
catch (Exception e)
{
Console.WriteLine("Error\nError \n" + e.Message + "\n" + e.StackTrace);
}
}
And this is my flex code:
var request:URLRequest = new URLRequest();
request.data = "Hello from flex";
request.url = URL;
request.method = URLRequestMethod.POST;
loader.load(request);
I am always getting 2 calls.
The line:
Console.WriteLine("Client accepted " + client.Connected + " " + client.Available);
called twice.
What am I missing?
Edit 1:
I can tell you for sure that the second call is empty, it’s not even seen in chrome JavaScript console, it’s like flex opening a connection, and waiting for some response or I don’t know what… but it sending no data.
Edit 2:
I been trying to send a true HTTP response a notice another thing, the second call is coming without waiting for the first call, if I am putting the response thread to short sleep(100 milliseconds in my test) then I am getting the second call before I been able to response for the first one.
P.S
Using Flex 4.6, Visual Studio 2010
After all it turn around that it were the crossdomain request. If you do not adding a crossdomain file in you www folder, flex will send you an empty message(if you will try to response this message with crossdomain, it want work).