Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sockets in J2ME

 
feda alshahwan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the followingcode that reads data from input socket and then casted to HTTPConnection to allow using HTTP methods but it is giving me casting exception errorHow can I do it " Read string from input stream and get the http header information andbody information from it" Thanks

 
Srinivas Vurrinkala
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi you cant typecast the socketconnection to httpconnection. You have to decide which connection had to be used. If you want header information while opening the connection typecast that to HttpConnection that is the standard way we do in J2ME.

HttpConnection conn =(HttpConnection)Connector.open(url);

 
feda alshahwan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for assistance my requirement is: The client wants to communicate with a server that provides restful web services.
So the client will send for example (GET /Addition?q1=5&q2=6 HTTP1.1) and the server will should parse the received message and extract the Addition and parameters and redirect it to the appropriate resource? So what is the best solution?

 
Srinivas Vurrinkala
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got what you want to do. For invoking restful services you just need to construct http url with above said parameters . The url can be this http://somesite.com/addition?q1=5&q2=6. This will definitely works out.


Regards
Srinivas
 
feda alshahwan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did what you told me but I got the following error:
Uncaught exception java/lang/IllegalArgumentException: Malformed address.
knowing that the code is:


The server side code is:

 
Space pants. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!