Hi, I am trying to send a simple HTTP message from Flex to a C # server, but it seems that I am getting tow calls, the first one is real and the second one is empty.
Why is this and how can I handle this?
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 just for testing Console.WriteLine("Client accepted " + client.Connected + " " + client.Available); SocketHandler handler = new SocketHandler(); ThreadPool.QueueUserWorkItem(handler.handleSocket, client); }
this is 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 flexible code:
var request:URLRequest = new URLRequest(); request.data = "Hello from flex"; request.url = URL; request.method = URLRequestMethod.POST; loader.load(request);
I always get 2 calls. Line:
Console.WriteLine("Client accepted " + client.Connected + " " + client.Available);
called twice. What am I missing?
Edit 1: I can tell you that the second call is empty, it doesnβt even appear in the Chrome Chrome console, it is like flex, it opens the connection and is waiting for an answer, or I donβt know what ... but it does not send any data.
Edit 2:
I am trying to send a true HTTP response message to another, the second call goes without waiting for the first call, if I put the response flow in a short sleep (100 milliseconds in my test), then I receive the second call before I can answer the first.
PS Using Flex 4.6, Visual Studio 2010