Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Use socket to receive binary data but the flash player keeps showing unhandled security problem

Guest
Nov 09, 2013 Nov 09, 2013

Hi,

        I am implementing an application to send/receive binary data from server. I study the documentation of security file of socket but it still doesn't work. My code are as follow,

Actionscript:

          suckit = new Socket("www.mysite.com", 843);

          suckit.writeUTFBytes("Hello server");

          suckit.flush();

Security file:

<?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="*.mysite.com" to-ports="843, 3496" />

</cross-domain-policy>

On the server side, the socket receives <policy-file-request/> and then write the security file to my client side flash application. However, my flash application seems to keep receiving

"Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: https://www.mysite.com/videoplayer.swf cannot load data from www.mysite.com:843."

Can someone give me some suggestions of solving this problem? Or else, is there any other way to receive binary data from server side?

TOPICS
ActionScript
932
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 09, 2013 Nov 09, 2013

are two different servers involved here?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 09, 2013 Nov 09, 2013

Thank you for your reply. No, only one server involved.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 09, 2013 Nov 09, 2013

then you must control the socket server.  are you sure it's setup correctly?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 10, 2013 Nov 10, 2013
LATEST

I think it is set up properly. My server code are as follows,

/*Server code*/

int main(int argc, char *argv[])

{

          /* listen on sock_fd, new connection on new_fd */

          int sockfd, new_fd;

          /* my address information */

          struct sockaddr_in my_addr;

          /* connector’s address information */

          struct sockaddr_in their_addr;

          socklen_t sin_size;

          struct sigaction sa;

          int yes = 1;

          if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1){

                    perror("Server-socket() error lol!");

                    exit(1);

          }

          else

                    printf("Server-socket() sockfd is OK...\n");

          if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {

                    perror("Server-setsockopt() error lol!");

                    exit(1);

          }

          else

                    printf("Server-setsockopt is OK...\n");

          /* host byte order */

          my_addr.sin_family = AF_INET;

          /* short, network byte order */

          my_addr.sin_port = htons(MYPORT);

          /* automatically fill with my IP */

          my_addr.sin_addr.s_addr = INADDR_ANY;

          printf("Server-Using %s and port %d...\n", inet_ntoa(my_addr.sin_addr), MYPORT);

          /* zero the rest of the struct */

          memset(&(my_addr.sin_zero), '\0', 8);

          if(bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {

                    perror("Server-bind() error");

                    exit(1);

          }

          else

                    printf("Server-bind() is OK...\n");

          if(listen(sockfd, BACKLOG) == -1) {

                    perror("Server-listen() error");

                    exit(1);

          }

          printf("Server-listen() is OK...Listening...\n");

          /* clean all the dead processes */

          sa.sa_handler = sigchld_handler;

          sigemptyset(&sa.sa_mask);

          sa.sa_flags = SA_RESTART;

          if(sigaction(SIGCHLD, &sa, NULL) == -1) {

                    perror("Server-sigaction() error");

                    exit(1);

          }

          else

                    printf("Server-sigaction() is OK...\n");

          /* accept() loop */

          while(1)

          {

                    sin_size = sizeof(struct sockaddr_in);

                    if((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) {

                              perror("Server-accept() error");

                              continue;

                    }

                    else

                              printf("Server-accept() is OK...\n");

                    printf("Server-new socket, new_fd is OK...\n");

                    printf("Server: Got connection from %s\n", inet_ntoa(their_addr.sin_addr));

                    pid_t pid1 = getpid();

                    /* this is the child process */

                    if (!fork())

                    {

                              /* child doesn’t need the listener */

                              close(sockfd);

                              for (int iii = 0; iii < 5; iii++) {

                                        int size = 0;

                                        char buffer [512];

                                        while (size <= 0) {

                                                  size = recv(new_fd, buffer, (sizeof buffer)-1, 0);

                                                  *(buffer+size) = 0;

                                        }

                                        printf("Received data => %s\n", buffer);

                                        char pPolicy[1024];

                                        FILE* fp = fopen("flashpolicy.xml", "rb");

                                        if (fp) {

                                                  int n = fread(pPolicy, 1, 1024, fp);

                                                  fclose(fp);

                                                  // printf("size = %d\n%s\n",n, pPolicy);

                                        }

                                        int m = send(new_fd, pPolicy, strlen(pPolicy), 0);

                                        printf("send size = %d\n", m);

                              }

                              close(new_fd);

                              exit(0);

                    }

                    else

                              printf("Server-send is OK (%d)...!\n", pid1);

                    /* parent doesn’t need this*/

                    close(new_fd);

                    printf("Server-new socket, new_fd closed successfully...\n");

          }

          return 0;

}

Besides, I have updated my security file as follows,

<?xml version="1.0"?>

<!DOCTYPE cross-domain-policy SYSTEM "https://www.mysite.com/cross-domain-policy.dtd">

<!-- I have downloaded the dtd to my server -->

<!-- Policy file for xmlsocket://socks.example.com -->

<cross-domain-policy>

   <!-- This is a master socket policy file -->

   <!-- No other socket policies on the host will be permitted -->

   <site-control permitted-cross-domain-policies="all"/>

   <!-- Instead of setting to-ports="*", administrator's can use ranges and commas -->

   <!-- This will allow access to ports 123, 456, 457 and 458 -->

   <allow-access-from domain="*.myspotcam.com" to-ports="843, 3496" />

</cross-domain-policy>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines