I made a custom server that accepts TCP connections on a certain port. I made a corresponding client that sends data to the server. The client writes to the socket and the server seems to accept it. In short, the server / client rig works. Now I want to re-create the client only this time, via Flex 4 / Flash Builder 4. How do I go about making my Flex 4 app connect to my custom server?
I used the following approach:
<fx:Declarations>
<s:HTTPService id="initialConnection"
url="theserverip:theserverport"
resultFormat="text" requestTimeout="5" showBusyCursor="true"
result="initialConnection_resultHandler(event)"
fault="initialConnection_faultHandler(event)" >
</s:HTTPService>
</fx:Declarations>
With that type of approach, the server doesn’t seem to be receiving any connections at all. And also, even though I set the requestTimeout to 5, my Flex app seems to continuously try to connect to the server because I rigged it so that the button when clicked will call this HTTPService also that certain button would get disabled and it will get enabled again after it the connection successfully connects, returned an error or if it timed out.
So with all these said, I want to ask you, what is the best approach to making my Flex app connect to my custom made server? Also I’m not really experienced with Flex so please try to elaborate on the answer.
Thanks in advance! 🙂
If you wrote a custom server that accepts TCP connections on a specific port, you probably don’t want to use HTTPService, which specifically send HTTP Requests. Based on your post, I assume your custom server would not know what to do with an HTTP Request.
I suggest looking into sockets and how they are used in the Flash Player. Since you already have a working client, I would expect it shouldn’t be too hard to convert it to ActionScript. My impulse is that if you can implement your client library without any Flex framework dependencies you’ll be better off in the long term.
All that said, I’d suspect that in 99% of the case, building your own server–and client–from scratch is probably not needed. There are plenty o existing server products that provide plenty of ways to get data back and forth.