Доброго времени суток! Помогите сделать отправку файла политики флеш клиенту, уже несколько дней парюсь, а всё что нахожу - ничего не работает =( Вот код сервера: | Код | import java.net.*; import java.io.*;
public class hello extends Thread { protected Socket clientSocket; private static ServerSocket serverSocket; public static void main(String[] args) throws IOException { ServerSocket serverSocket = null;
try { serverSocket = new ServerSocket(10008); System.out.println ("Connection Socket Created"); try { while (true) { System.out.println ("Waiting for Connection"); new hello (serverSocket.accept()); } } catch (IOException e) { System.err.println("Accept failed."); System.exit(1); } } catch (IOException e) { System.err.println("Could not listen on port: 10008."); System.exit(1); } finally { try { serverSocket.close(); } catch (IOException e) { System.err.println("Could not close port: 10008."); System.exit(1); } } }
private hello (Socket clientSoc) { clientSocket = clientSoc; start(); }
public void run() { System.out.println ("New Communication Thread Started");
try { PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); // out.println(); BufferedReader in = new BufferedReader( new InputStreamReader( clientSocket.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) { System.out.println ("Server: " + inputLine); out.println(inputLine);
if (inputLine.equals("Bye.")) break; }
out.close(); in.close(); clientSocket.close(); } catch (IOException e) { System.err.println("Problem with Communication Server"); System.exit(1); } } }
|
Вот код клиента: | Код | /* connect to socket */ var socket = new Socket("localhost", 10008); socket.connect; socket.flush; /* state of connect to socket */ socket.addEventListener(Event.CONNECT,socketConnected); function socketConnected(e:Event):void{ trace("client - socket connected", socket.connected); } /* read the string from the socket*/ socket.addEventListener(ProgressEvent.SOCKET_DATA,socketData); function socketData(e:ProgressEvent):void{ var read_socket=socket.readUTFBytes(socket.bytesAvailable); trace(read_socket); } socket.writeUTFBytes('HELLO');
socket.close;
|
Сервер получает только <policy-file-request> Нашел вот такую штуку на форуме: | Код | try { System.out.println("-> Security server started..."); serverSocket = new ServerSocket(10007, 128, InetAddress.getByName("localhost")); Socket client; DataOutputStream out; DataInputStream in; // Reading crossdomain.xml FileInputStream xmlFile = new FileInputStream("c:/policy.xml"); int xmlBytesCount = xmlFile.available(); byte[] xmlBytes = new byte[xmlBytesCount + 1]; xmlFile.read(xmlBytes, 0, xmlBytesCount); xmlBytes[xmlBytesCount] = 0; xmlFile.close(); byte[] policyRequest = new byte[23]; for (;;) { client = serverSocket.accept(); out = new DataOutputStream(client.getOutputStream()); in = new DataInputStream(client.getInputStream()); in.read(policyRequest, 0, 23); out.write(xmlBytes, 0, xmlBytesCount + 1); out.flush(); System.out.println(":: FSS :: Policy sended to " + client.toString()); client.close(); } } catch (Exception e) { e.printStackTrace(); }
|
Вставляю сразу после объявления main, но всё остальное просто перестаёт работать=( ПОМОГИТЕ ПОЖАЛУЙСТАААА
|