Hitting api on server using websocket connection in android

I am working on websocket connection to communicate with server. Now, we have established a connection and able to send and receive message using Autobahn library.

Here is the code:

private void start() { // wsuri is the url which has to be hit for connecting to the server i.e // "ws://hostname:port " final String wsuri = "ws://" + mHostname.getText() + ":" + mPort.getText(); // showing status on the UI. mStatusline.setText("Status: Connecting to " + wsuri + " .."); // enabling disconnect button clicking on which the connection will be // disconnected. setButtonDisconnect(); try { mConnection.connect(wsuri, new WebSocketConnectionHandler() { @Override public void onOpen() { // If connection is open, then status will be updated to // "connected to..." mStatusline.setText("Status: Connected to " + wsuri); savePrefs(); // enabling mSendMessage button and mMessage edit Text. mSendMessage.setEnabled(true); mMessage.setEnabled(true); } @Override public void onTextMessage(String payload) { Log.d("ss", payload); alert(payload); } @Override public void onClose(int code, String reason) { // If connection is lost, alert will be shown connection is // lost and status will be set to "Ready". alert("Connection lost."); mStatusline.setText("Status: Ready."); setButtonConnect(); // disabling mSendMessage button and mMessage edit Text. mSendMessage.setEnabled(false); mMessage.setEnabled(false); } }); } catch (WebSocketException e) { Log.d(TAG, e.toString()); } }

We just have a single method onTextMessage(String payload) to handle response from server.

and to send message to server we use mConnection.sendTextMessage(mMessage.getText().toString());

But now we are facing issue that how to hit api on that server?or lets say I want some list of devices or device_Status etc how it will happen??

Any idea how to do that?? At present I am thinking of sending some "key":"pair" value in message in form of json, by which the server will identify what request I have made...

I am still not sure whether this is the right way? Please if somebody can help me in this.

Category:android Views:1 Time:2018-02-08

Related post

  • Send an email notification via Gmail SMTP server using SSL connection 2012-01-12

    I am trying to send an email notification via Gmail SMTP server using SSL connection. But no email is getting. Even no error is reported there.My method send() is giving below.Please help.I am using JSF2 . public void send() { Properties props = new

  • how to connect sql server using JTDS driver in Android 2011-10-03

    i am new in android.. i want to connect sql server using JTDS driver. can any one tell me.. thnx in advance... --------------Solutions------------- Getting error "ClassNotFoundException" while using JTDS on ANDROID to direct access SQLSERVER? After 3

  • send json string as request to server using https connection 2011-02-25

    In my android application i would like to send a json object with username and password as string to the server. Could you please let me know how i can achieve this using https connection. Please share your valuable suggestions. Thanks in advance :)

  • Setting SQL Linked Server using DSN Connection 2011-08-17

    We have Ctree Database ODBC Drivers which is installed and configured on our local system. We have DSN Connection which is ready to use. Using DSN Connection, i need to establish SQL Linked Server Connection. I am very new to SQL Linked Server Connec

  • problem regarding transferring file to server using socket connection 2010-12-13

    I'm able to transfer a file to the server using Java, but I'm not able to transfer the file using socket programming in Android. How do I do this? Here is my Java code: import java.io.BufferedReader; import java.io.File; import java.io.FileInputStrea

  • Re-use HTTPS connections in Android? 2011-12-27

    I have an app that needs to make a series of HTTPS connections to a backend server. These connections happen in response to user input, so it is feasible to re-use the HTTS session. Experimentation on other platforms (iOS) has shown that this approac

  • Can we communicate client and server using SOAP UI in Android? 2011-06-09

    provide any related links. If yes it's fine. If NO why? suggest me. --------------Solutions------------- Not sure what exactly you mean. SOAP UI itself is a windows application. Android of course can communicate with a server using SOAP messages. I d

  • SQL server 2008 R2 connection error / android 2011-11-30

    I have a problem with making connection to local SQL server 2008 R2, here is code: System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:jtds:sqlserver://"; String dbName = "podmiot"; Stri

  • What java api can we use to connect to jUDDI V3 in an upgrade from V2? 2010-01-29

    We are upgrading some of our systems including a move up to jUDDI V3 from V2. In the past we used uddi4j in our java code to access the UDDI server, but uddi4j doesn't seem to have continued to V3. Extensive Google time leaves me thinking there is no

  • PHP SMTP server using sockets: connection refused 2010-09-10

    In one of my personal project I am developing a basic SMTP server in php. It's ready and working when I launch it on its own from the command line; I access it correctly through telnet and it is responding correctly to SMTP commands and I access it c

  • Hitting an http server using Socket 2011-04-22

    I am trying to hit a webserver using a simple Socket rather than using the wrappers made available. For whatever reason, I can't get it to receive the response. What is wrong with the code below: class Program { static void Main(string[] args) { Sock

  • How to use fb connect in Android app? 2012-04-08

    public class FacebookConnect extends Activity { Facebook facebook = new Facebook(""); String FILENAME = "AndroidSSO_data"; private SharedPreferences mPrefs; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState

  • Access a private web server using static IP from Android Application 2015-01-19

    I want to access a Oracle web service in my Android application. But the web service is in my company's server so public can not access it. But our Android app is going to be used by public. Is there a way to use that web service and connect to the s

  • Connect SBCL on Windows to SQL Server using Integrated Authentication 2010-01-11

    What is the path of least resistance in getting an SBCL application running on Windows to connect to a SQL Server instance, using integrated authentication? I have found posts on connecting from CL-SQL to SQL Server using ODBC connections but as far

  • Can I connect with WebSocket in an Android app? 2011-08-01

    I have an Android app and I want to send a text from the Android application to the webpage using HTML5 WebSocket. Is this possible and if so how? --------------Solutions------------- A simple google search for 'android websockets' turned up this. He

  • What is the correct way to write server name for connecting a remote sql server? 2011-01-23

    In Visual Studio, I'm trying to connect to my staging db server. In server name field, I've tried to fill with my server's ip address, but it didn't work. I'm sure I've enabled access for the ip address in Sql Server configuration. My guess is that t

  • Would it be possible to use WebSockets as a poor-mans proxy? 2012-04-12

    Im thinking a web browser would fetch a document from a server, the document then sets up a websocket to the server, ie communication link. Would it then be possible for the server to fetch any website/document the user types in and return it over th

  • How to use Facebook Connect and Facebook Application android 2011-07-10

    How to use Facebook Connect in android to get permission from Facebook to update status from my application. Please give some example. I'm struggling with this for past one week. Thanks, Shanmugam --------------Solutions------------- did you try this

  • Reusing an HTTP connection in Android 2011-07-20

    I am trying to re-use a connection in Android, and a quick google search finds this: http://foo.jasonhudgins.com/2010/03/http-connections-revisited.html However, I tried that, and if I use something like Wireshark, I can see I am still getting HTTP F

  • How to set secure websocket connection using websocket-server and node.js 2011-08-26

    I can't set secure websocket connection using websocket-server and node.js server side var options = { key: fs.readFileSync(PRIVATE_KEY), cert: fs.readFileSync(CERTIFICATE) }; // create web server var server = ws.createServer(options); server.listen(

  • "websocket connection invalid" when using nginx on node.js server 2012-02-13

    I'm using Express.js to create a server to which I can connect using web sockets. Even though it eventually seems to work (that, is connects and passes an event to the client), I initially get an error in Chrome's console: Unexpected response code: 5

  • Can I open a websocket connection to a local server running on an arbitrary port? 2011-05-17

    I have a local server outputting my real-time home sensor data, and I want to visualize it in my browser. My question is, can I use a websocket to open the connection from my browser to the local server? How would I go about doing that? The local ser

  • Connecting to remote server using java and ssh key 2009-09-11

    Does anyone have any code for connecting to a remote server using java and an ssh key. We dont have a password for this server, we just use our username and our ssh keys --------------Solutions------------- jsch is a pure java SSH implementation that

  • Using Javascript to connect with server using protocol other than HTTP 2010-09-26

    Can Javascript be used to connect with a server with a protocol other than HTTP or FILE? Ideally, I would like to connect to an SMTP server using Javascript. --------------Solutions------------- Not possible due to security constraints in the browser

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.124 (s). 11 q(s)