Since Javascript does not have any functionality for exchanging data on raw sockets, I decided to use the Java applet - and in the case when the user turned off java applets in their browser, a flash modem that must be integrated with Javascript, I tried with jsxmlsocket as well as haxejssocket only to solve the same problem
Now the server application is written in Java, and communication works fine on the java applet. But the flash seems to be the problem.
The first text that the flash receives is the response to <policy-file-request /> providing access to all domains and ports. This works great as sockets start to bind.
Here is the Javascript code that runs when data is received:
socket.onData = function(data) {
alert(data);
parse(data);
}
Now, here is the problem. After the response to <policy-file-request /> is sent, another 5 lines of text are sent. Of course, it is expected that I will see 5 warning boxes with the text sent in it. This does not seem to be the case. Instead, I see 5 warnings responding to <policy-file-request /> in this. It seems like something is being sent because the OnData function seems to be triggered at the right time, but for some reason, the data appears to be the first line of text sent to it.
Java thread that takes care of data transfer:
LinkedBlockingQueue<String> outQueue=new LinkedBlockingQueue<String>(1000);
public Thread checkSendLoop=new Thread(){
public void run(){
try{
OutputStream out=socket.getOutputStream();
while (true){
String mes=outQueue.take();
mes=mes.replace("\n", "").replace("\r", "");
mes=mes+"\0";
out.write(mes.getBytes());
out.flush();
}
}
catch (Exception e){
System.out.println("FATAL : Data to a client will not be sent anymore.");
outQueue.clear();
outQueue=null;
}
}
};
To send data, the send function is called:
public void send(String s){
Queue<String> testQueue = outQueue;
s=s+" "+getUnixTime();
if (testQueue!=null){
System.out.println("SENDING "+nick+" - "+s);
testQueue.add(s);
}
}
As you can see, all sent data ends with a zero byte or \ 0. Maybe this answers?
. , - " ", , , .
, , Telnet Java.
: , . , script <policy-file-request/> onData. "".