A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Need some help with simple socket server

Threaded View

  1. #1
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268

    [RESOLVED] Need some help with simple socket server

    I've created a simple Java server app and an AS3 client. Basically AS3 client only connects to the server on localhost:4444 using XMLSocket.
    Java server runs great. It listens to the port 4444 and even reacts to my as3 client connection.


    AS3 client is supposed to create a new TextField and "Got it" text to it on connection event. That's where the problem appears.

    I can see it tries to get a policy file. But I have this file placed into the same folder with my Java server:



    Here's its source:
    <?xml version="1.0"?>
    <!DOCTYPE cross-domain-policy
    SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
    <cross-domain-policy>
    <allow-access-from domain="*"/>
    </cross-domain-policy>


    Here's the source of the testApp.jar

    Actionscript Code:
    package com.konstantin;

    import java.io.*;
    import java.net.*;

    public class Server {

      public static void main(String[] args) throws IOException {
        System.out.println("Welcome to Server side");
        BufferedReader in = null;
        PrintWriter    out= null;

        ServerSocket servers = null;
        Socket       fromclient = null;

        // create server socket
        try {
          servers = new ServerSocket(4444);
        } catch (IOException e) {
          System.out.println("Couldn't listen to port 4444");
          System.exit(-1);
        }

        try {
          System.out.print("Waiting for a client...");
          fromclient = servers.accept();
          System.out.println("Client connected");
        } catch (IOException e) {
          System.out.println("Can't accept");
          System.exit(-1);
        }

        in  = new BufferedReader(new
         InputStreamReader(fromclient.getInputStream()));
        out = new PrintWriter(fromclient.getOutputStream(),true);
        String   input;

        System.out.println("Wait for messages");
        while ((input = in.readLine()) != null) {
         if (input.equalsIgnoreCase("exit")) break;
         out.println("S ::: "+input);
         System.out.println(input);
        }
        out.close();
        in.close();
        fromclient.close();
        servers.close();
      }
    }

    The source for Client can be found in attachments.

    What am I doing wrong?
    Attached Files Attached Files
    Last edited by caseyryan; 08-04-2010 at 12:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center