0

In my web-app the client pings the server (tries to contact a ping servlet on the server) wheere the address / resource locator of the servlet is :

"192.168.43.187/server/ping?" + new ClientAddress().getNetworkIP();

Till now the client has been sending it's network IP to the server with every ping. I wanted to add another piece of information with this URL,which is new GregorianCalendar().getTimeInMillis(); .

How do I send this along ?

Note :

In the URL, ping is a servlet

saplingPro
  • 20,769
  • 53
  • 137
  • 195

2 Answers2

2
"192.168.43.187/server/ping?ip=" + new ClientAddress().getNetworkIP() + 
    "&time=" + new GregorianCalendar().getTimeInMillis();

You will need to change "ping" servlet in order to read those parameters.

1

I would construct the URL thus:

"192.168.43.187/server/ping?ip=" + (new ClientAddress().getNetworkIP()) + "&time=" + (new GregorianCalendar().getTimeInMillis());

and use the servlet request method ServletRequest.getParameter() to extract the values.

Note that ServletRequest.getRemoteAddr() gives you the client address. Do you need to pass it explicitly ? Additionally, constructing a URL by string concatenation works in this trivial scenario, but as soon as you pass values that include characters such as spaces etc. you'll need to encode these values.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440