Re: Getting data from nodejs server at GWT

116 views
Skip to first unread message

Ümit Seren

unread,
Jun 8, 2012, 8:55:29 AM6/8/12
to google-we...@googlegroups.com
I have not much experience with node.js but I would recommend to use Chrome's Developer Tool or FireBug to check the XHTML request and response. 


On Sunday, June 3, 2012 5:25:38 PM UTC+2, Kuenga wrote:
HI,

I have created a web server using NodeJS. At the server side, i have
string of numbers (2,3,4). I want to convert it to Array object at the
GWT object. I was not able to do.

So was trying to display simple text message at GWT using the following code:

Window.alert("Connecting to server");
               String Strurl = "http://127.0.0.1:1337/";
               RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
URL.encode(Strurl));
               try {
                       Request request = builder.sendRequest(null, new RequestCallback() {
               public void onError(Request request, Throwable exception) {
                       // Couldn't connect to server (could be timeout, SOP
violation, etc.)
               }
                       public void onResponseReceived(Request request, Response response) {
                       if (200 == response.getStatusCode()) {
                               // Process the response in response.getText()
                               Window.alert(response.getText());
                       }
                       else {
                       //       Handle the error.  Can get the status text from
response.getStatusText()
                       }

               }
               });
                       Window.alert(request.toString());
               } catch (RequestException e) {

               }


Got the 'Conecting to Server' alert message but do not get the alert
message inside the RequestBuilder call back.

Below the javascript code of Nodejs

http.createServer(function (req, res) {

res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("From node js");
       res.end();
}).listen(1337, '127.0.0.1');

How can i get the data at the GWT side from NodeJS server javascript code ? 

Thanks

Thomas Broyer

unread,
Jun 8, 2012, 9:36:23 AM6/8/12
to google-we...@googlegroups.com


On Sunday, June 3, 2012 5:25:38 PM UTC+2, Kuenga wrote:
HI,

I have created a web server using NodeJS. At the server side, i have
string of numbers (2,3,4). I want to convert it to Array object at the
GWT object. I was not able to do.

So was trying to display simple text message at GWT using the following code:

Window.alert("Connecting to server");
               String Strurl = "http://127.0.0.1:1337/";
               RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
URL.encode(Strurl));

Unless you run your GWT app from http://127.0.0.1:1337/ (which I doubt) or your NodeJS server at that URL sends back an appropriate Access-Control-Allow-Origin response header (see http://www.w3.org/TR/cors/ ), then onError will be called (and in browsers that do not support CORS, such as Internet Explorer, RequestBuilder#sendRequest() will throw)

Reply all
Reply to author
Forward
0 new messages