6 Replies Latest reply on Oct 29, 2008 12:10 PM by ice9_us

    Flex and C++

    sri harsha namala Level 2
      Hi Every One,

      I have two applications ,among them one will be flex and the other one is C++ application, Flex will be the front end application , When i click the button in the front end parameters must be transferred from flex to C++ and it should process there and it should returned to flex. I want to use Server also (Tomcat 5.5) .How to do this???

      Thanks in advance........
        • 1. Re: Flex and C++
          ice9_us
          i have done this by using the httpservice...
          i wrote inside my c app a listen function..
          that is the only way i know of at this time.

          the httpservice connects to my port..
          i parse the data... and kick back xml data which is read into an array or xmllist...

          do you have any idea how to change the color of a datagrid background based on text in the data you get back?

          httpservice -> get data..

          if rowdata == someline of data ){
          set background black
          else if ( rowdata == someline of data) {
          set background blue.....


          • 2. Re: Flex and C++
            tiaan.wessels
            I presume you know how to to socket communications in C. The simplest of patterns for this scenario is setup a security policy server on port 843 (default Flash policy server port - see Flash security white paper). Setup a listening socket on some other port of your own choice which will accept TCP/IP connections. Use flash.net.Socket to connect to your server socket. When you do this, flash will transparently connect to port 843 first. Your program should now serve it with a zero terminated XML file according to the cross-domain policy XML format. Provided this file is correctly setup, the flash player will now proceed to connect to your actual TCP/IP port. You may now exchange data as you wish. In my opinion, easiest is 4 byte number in network byte order indicating length of payload to follow and then the payload in XML (you need an external data format - XML easiest in Flex as it is really geared towards this but you might want to have a look at Adobe ADF as well if bandwidth is a problem). In your C app, read the 4byte length and then so many bytes thereafter, parse the XML, do something useful and return the answer in XML which you can now hand over to the top-level XML class for inspection in your Flex app.
            Hope you come right.
            • 3. Re: Flex and C++
              sri harsha namala Level 2
              Can u give me the sample code please...........
              • 4. Re: Flex and C++
                tiaan.wessels Level 1
                I'm sorry but i don't have a self-contained example and am buried under work so it might take a while to concoct up something. Which part are you referring to, the C or Flex part or both ?
                • 5. Re: Flex and C++
                  ice9_us Level 1
                  Sorry i just saw this or i would have posted sample code long ago..
                  Let me know if you need anything else..
                  when you accept a connection you call simple read/write functions to pass data...
                  I am more than happy to help..



                  int main(int argc, char **argv) {

                  FILE *fp;
                  int listenfd, connfd, n, status ;
                  const int on = 1;
                  pid_t childpid;
                  pid_t parent;
                  socklen_t clilen;

                  struct sockaddr_in cliaddr, servaddr;

                  buff2=malloc(512);
                  host_connect=malloc(14);

                  listenfd = socket(AF_INET, SOCK_STREAM, 0);
                  bzero(&servaddr, sizeof(servaddr));
                  servaddr.sin_family = AF_INET;
                  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
                  servaddr.sin_port = htons(Put your port number here);

                  setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
                  setsockopt(listenfd, SOL_SOCKET, TCP_NODELAY, &on, sizeof(on));

                  bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
                  listen(listenfd, 300);


                  /** When testing network stuff here.. use UNIX telnet stuff.. some apps are sending extra data...
                  this is the reason you see me check for the # of data waiting to be read before i even start working...
                  I also have functions which check for buffer over flow attacks and other types of hacks...
                  ***/

                  if ( ( parent = fork()) == 0 ) {
                  for ( ; ; ) {
                  clilen = sizeof(cliaddr);
                  if ( (connfd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen)) < 0 ) {
                  if ( errno == EINTR ) {
                  continue;
                  } else {
                  perror("accept");
                  }
                  }
                  • 6. Re: Flex and C++
                    ice9_us Level 1
                    /** When testing network stuff here.. use UNIX telnet stuff.. some apps are sending extra data...
                    this is the reason you see me check for the # of data waiting to be read before i even start working...
                    I also have functions which check for buffer over flow attacks and other types of hacks...
                    ***/
                    ------------------------------------------------------------------------------------------ ------------------
                    you don't see this take place.. i did a cut and P. of some of my basic stuff to get ya going..
                    if you need any more help let me know.. I will be more than happy do do anything i can..

                    I am very sorry i didn't see this post until now..