2

In the Java ME platform that I am using I have only SocketConnection class to connect to a distant server. For example I can create a connection to a server socket on the given ip using Connector.open("socket://"+ip+":"+port).

What I want is to implement an HttpConnection that will use http protocol, a url and port 80 as parameters. I imagine it will be something like Connector.open("http://www.google.com:80) to be able to send GET, POST, DELETE, PUT requests to the server afterwards.

Is there a way to get the ip via url address and then connect to this ip using http protocol? Or if it isn't supported by my platform, then I have to stick to using sockets? I know my question can seem a little abstract, so ask if you need any clarifications.

Limbo Exile
  • 1,321
  • 2
  • 21
  • 41

1 Answers1

1

You have to stick to using sockets. If the Java ME platform that you are using have only SocketConnection, a call to Connector.open("http://www.google.com:80") will throw an exception.

Telmo Pimentel Mota
  • 4,033
  • 16
  • 22
  • Indeed it does throw an exception that indicates that the platform doesn't support the type of connection specified. What about using `Connector.open("socket://www.google.com:80")`? I thought it could work but I get `IOException: cannot open socket using DNS`. – Limbo Exile Mar 15 '13 at 12:54
  • Your platform is also restrictive with Domain Name Service and you will have to replace www.google.com with an IP. – Telmo Pimentel Mota Mar 18 '13 at 11:27