1

im trying to implement a simple comet app to just send data and recive data, my client side is written on java and the server is in node.js, im trying to implement it from the client side with HttpUrlConnection but it seems that when i try to write to the server it doesnt respond me. so how can code the server to respond? (currently using http.createServer(function(req, res){...}).listen(8124);

2
  • A little more detail please. You've told us on client side you're using HttpUrlConnection, but what type of Http (get/post)? What url? What are you using on the server side? Commented Dec 23, 2010 at 12:41
  • ill post my code on sunday when i get to work for the mean while i use post method, the url is the server ip adress + port and im using the inputStream and outputStream for the the HttpURLConnection to write and recive data from the server and im using standart function for request and response on the server side maybe I need to use the net.Stream object but if I use it how can I pass a writable and readble stream at the same time to the server, and another thing my last issue is to implement the server to push data to client but thats another issue+) Commented Dec 23, 2010 at 17:02

2 Answers 2

1

I'm doing something similar to that with an Android app. I can't say that this is the "right" way to do it, but I'm using these classes in my project (to make POSTs and check the responses):

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

To implement I'm doing something to the effect of

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(/*...(String) url...*/);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("key", "value"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost); // <-- this has useful info

To actually get useful stuff from the server I'm using JSON because, IMHO, XML parsing is a huge pain in Java.

So these are the classes I use for parsing the JSON that nodejs spits out at me.

import org.json.JSONArray;
import org.json.JSONObject;

...

JSONObject jObject = new JSONObject(EntityUtils.toString(response.getEntity()));
JSONArray datasets = jObject.getJSONArray("blahblahblah");
Sign up to request clarification or add additional context in comments.

Comments

0

Having used it (quite easily) in my own Android app, I recommend Socket.IO-client Java.

It's a "full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.