
Signature
Knute Johnson
email s/nospam/knute/
thanks you seemed to have prooved that a regular applet can receive
udp datagram from its server though all that remains mysterious and my
server does not work:
Facts:
- There is a firewall on my server side and the windows xp firewall
here on my desktop
- your udp applet http://www.knutejohnson.com/echo.html works fine
from my desktop
- your udp applet does not work with my c# echo udp (I plugged it to
my server)- server receives packets and echo them back but they nerver
reach back the applet
-my c# echo udp works fine with a standalone java app from my local
computer
-my applet (which does pretty much the same than knute's one) does not
work with my c# echo udp server - - server receive packets and echo
them back but they nerver reach back the applet
- if my applet is signed then it works fine with my c# echo udp server
I need this applet working without being signed !!
Any clue ??
thanks
here is new version of my c# echo udp server :
protected void StartUDP()
{
Socket soUDP = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
try
{
//60 sec timeout
soUDP.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, 3000);
// On doit lier la Socket à un port d'écoute sur la
machine. On choisit également de se mettre en écoute sur toutes les
interfaces réseaux présentes (IPAddress.Any).
soUDP.Bind(new IPEndPoint(IPAddress.Any,
(int)Application["port"]));
Application["log"] = Application["log"] + "isBinded<br>";
Application["isStarted"] = true;
Application["serverStatus"] = "UDP server isStarted at " +
DateTime.Now + "<br>";
Application["log"] = Application["log"] + "start waiting
at " + DateTime.Now + "<br>";
while (!((Boolean)(Application["stopRequested"])))
{
//if datagram receveided is bigger than 12 exception
will be thrown on receive
Byte[] received = new Byte[12];
// Empty endpoint
EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
try
{
//remoteEP will be instanciated by the method
// with remote sender info
int bytesReceived = soUDP.ReceiveFrom(received,
ref remoteEP);
//echoes back
soUDP.SendTo(received, remoteEP);
String dataReceived =
System.Text.Encoding.ASCII.GetString(received);
IPEndPoint ip = (IPEndPoint)remoteEP;
Application["log"] = Application["log"] +
"Datagram packet received from "+ ip.Address +":"+ip.Port+ "<br>";
Application["log"] = Application["log"] +
"Datagram packet length=" + bytesReceived + " dataReceived=" +
dataReceived + "<br>";
Application["log"] = Application["log"] + "Echoed
it back to " + ip.Address +":"+ip.Port+ "<br>";
}
catch (Exception t)
{
// Here it is a timeout (but not a
sockettimeoutexception)
// Application["log"] = Application["log"] + "" +
t.Message;
}
}
}
catch (Exception e)
{
Application["serverStatus"] = "UDP server probably stoped
on exception at " + DateTime.Now + "<br>";
Application["isStarted"] = false;
Application["log"] = Application["log"] + "Exception at "
+ DateTime.Now + "<br>";
Application["log"] = Application["log"] + e.Message +
"<br>";
soUDP.Close();
}
Application["isStarted"] = false;
Application["log"] = Application["log"] + "finally closing
server";
Application["serverStatus"] = "UDP server stoped at " +
DateTime.Now + "<br>";
soUDP.Close();
}
Knute Johnson - 18 Apr 2007 17:45 GMT
> thanks you seemed to have prooved that a regular applet can receive
> udp datagram from its server though all that remains mysterious and my
[quoted text clipped - 104 lines]
>
> }
Let's see the complete code of your applet.

Signature
Knute Johnson
email s/nospam/knute/
oliviergir@gmail.com - 18 Apr 2007 18:20 GMT
here is the class which is supposed to measure the ping time within
the applet
package P;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.*;
import java.io.*;
public class Ping {
static InetAddress serveur;
static String payload;
static DatagramSocket socket;
static DatagramPacket dataSent;
static DatagramPacket dataRecieved ;
public static String getRemotePage(String urlPath)
{
try {
//On crée l'URL
URL url = new URL(urlPath);
//On crée une connection vers cet URL
URLConnection connection = url.openConnection( );
//On récupère la taille du fichier
int length = connection.getContentLength();
//Si le fichier est inexestant, on lance une exception
if(length == -1){
System.err.println("empty page !!");
}
//On récupère le flux du fichier
InputStream is = new
BufferedInputStream(connection.getInputStream());
//On prépare le tableau de bits pour les données du fichier
byte[] data = new byte[length];
is.read(data);
String s=new String(data);
System.out.println(" page content="+s);
return s;
}
catch (Exception e)
{
e.printStackTrace();
return "";
}
}
public static void getReady(BandePassante monapplet) {
try {
String s=getRemotePage(monapplet.getCodeBase()+"UDPServer.Aspx?
start=Y");
if (s.indexOf("Server started")<0)
System.err.println("Could not start UDP Server!!");
else
System.out.println("page="+s);
serveur = InetAddress.getByName(monapplet.host);
payload="";
int length = payload.length();
byte buffer[] = payload.getBytes();
dataSent =
new DatagramPacket(buffer,length,serveur, 7777);
socket = new DatagramSocket();
socket.setSoTimeout(800);
dataRecieved = new DatagramPacket(new byte[length],length);
// let some time to the server start
Thread.sleep(300);
for(int i=0;i<2;i++)
System.out.println("First drop few ping :"+Ping.go());
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static long go() {
try {
System.out.println("send packet");
long t1=System.currentTimeMillis();
socket.send(dataSent);
socket.receive(dataRecieved);
long t2=System.currentTimeMillis();
return (t2-t1);
}catch (Exception e)
{
e.printStackTrace();
return -1;
}
}
}
Knute Johnson - 18 Apr 2007 18:35 GMT
> here is the class which is supposed to measure the ping time within
> the applet
[quoted text clipped - 91 lines]
> }
> }
Does it work if you set the data of the outbound packet to something
other than ""?

Signature
Knute Johnson
email s/nospam/knute/
oliviergir@gmail.com - 18 Apr 2007 19:02 GMT
with your applet the packet is chosen by user and it does not work
with any
oliviergir@gmail.com - 18 Apr 2007 19:29 GMT
A regular (not signed) applet is only allowed to receive UDP packets
from "its server" right ?
A signed applet can receive UDP packets from any host , right ?
maybe there is a network device somewhere that make impossible for my
applet to realise that the packet is actually coming from "its
server".
That would explain why it only works when my applet is signed ..
what do you think of that track ?
Knute Johnson - 18 Apr 2007 23:21 GMT
> A regular (not signed) applet is only allowed to receive UDP packets
> from "its server" right ?
[quoted text clipped - 5 lines]
> That would explain why it only works when my applet is signed ..
> what do you think of that track ?
I don't know what that would be but what does you network look like?
Where is the server located?

Signature
Knute Johnson
email s/nospam/knute/
oliviergir@gmail.com - 18 Apr 2007 18:34 GMT
more simple :
see how your applet is plugged to my server
http://66.51.207.91/testUDP.html
and the server really receives the packet see output here
http://66.51.207.91/UDPServer.aspx?action=start
but your applet never receives answer, at least on my desktop.
Does it on yours ?
Knute Johnson - 18 Apr 2007 23:20 GMT
> more simple :
>
[quoted text clipped - 6 lines]
> but your applet never receives answer, at least on my desktop.
> Does it on yours ?
No. It doesn't work if run your applet here. The server site gives an
error too.

Signature
Knute Johnson
email s/nospam/knute/