Server i java - client i java - client i flash læser kun sig selv
Hejsa.Jeg er stødt på et lille problem. Jeg er ved at udvikle et skørt lille program. Jeg står med en client i java som via sockets smider en en string ud til en server. selv samme server er i stand til at håndtere flere clienter. Derfor har jeg også lavet en clien i flash der skal bruge den streng der sendes fra java-clienten.
Mit Problem er at flash-client kun kan se det info den selv skriver til socketen.
Hvis der var nogen der hadve et forslag til hvad der kunne være galt vil jeg sætte stor pris på det
Java-clienten fungerer som den skal... den skriver bare en streng ud til socketen
=========================================
Server-kildekoden START
=========================================
import java.io.*;
import java.net.*;
public class Server
{
private static boolean done = false;
private ServerSocket socketListener = null;
private void control()
{
int port = 4444;
System.out.println("The server listens on port: " + port);
try
{
socketListener = new ServerSocket(port);
int clientNo = 0;
while (true)
{
Socket client = socketListener.accept();
clientNo++;
System.out.println("\tClient " + clientNo + " is now logged in");
new handler(client, clientNo).start();
}
}
catch(IOException e)
{
}
}
public static void main(String[] args)
{
Server appl = new Server();
appl.control();
}
private class handler extends Thread
{
private Socket client;
private int clientId;
public handler(Socket socket, int id)
{
client = socket;
clientId = id;
}
public void run()
{
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(client.getOutputStream(), true);
out.println("You are client no " + clientId);
String input;
while ((input = in.readLine()) != null)
{
//Flash-Message terminator
char EOF = (char)0x00;
if (input.equalsIgnoreCase("End"))
{
System.out.println("\tClient " + clientId + " is logged out ");
out.println("\tClient " + clientId + " is logged out "+ EOF);
out.flush();
break;
}
if (input.equalsIgnoreCase("EndServer"))
{
System.out.println("\tClient " + clientId + " is logged out ");
System.out.println("Server closes for new clients");
out.println("\tClient " + clientId + " is logged out "+ EOF);
out.println("Server closes for new clients"+ EOF);
out.flush();
in.close();
out.close();
client.close();
socketListener.close();
}
else
{
//System.out.println(clientId+" - "+input);
out.println(clientId+" - "+input + EOF);
out.flush();
}
}
}
catch(IOException e)
{
}
}
}
}
================================================
Server kildekode slut
================================================
================================================
FLASH client kilde start
================================================
mySocket = new XMLSocket();
mySocket.onConnect = function(success)
{
if (success)
msgArea.htmlText += "Server connection established!"
else
msgArea.htmlText += "Server connection failed!"
}
mySocket.onClose = function()
{
msgArea.htmlText += "Server connection lost"
}
XMLSocket.prototype.onData = function(msg)
{
trace("MSG: " + msg)
msgArea.htmlText += msg
}
mySocket.connect("localhost", 4444)
//--- Handle button click --------------------------------------
function sendMsg()
{
if (inputMsg.htmlText != "")
{
mySocket.send(inputMsg.htmlText + "\n")
}
}
===============================================
FLASH KILDE SLUT
===============================================