Customer Service Chat
Get quote & make Payment
Android Development Project, JAVA Programming
I have an Android mobile app project that I''m trying to get profiles to transfer by connecting to a server at 22.214.171.124 port 1337. I have to send a json string to the server and receive a json string back with everyone that is connected to the server. Here is a more detailed description on how the server works:
First, when you first connect to the server, the server will assign a socket address to you (see
In other words, the server will detect your IP address and your port number, and it will combine these two to create and assign a socket address to you (e.g. 123.456.789.0:567). The server maintains these sockets addresses inside an array, so the server knows who is connected. When you disconnect, the server will remove your socket address from the array. Pretty simple.
Second, the server is a stream server that looks for complete JSON objects in its input stream (it is not an HTTP server). So how does the server know that a complete JSON object has arrived? Simply by looking for two }} termination characters in the input stream. So for when a client first connects, it will ask the server to broadcast (you will see what broadcast means in a minute) the following JSON object:
"message": "I like iOS!",
The server will recognize the ending }} characters and will parse the JSON object as follows:
The to field. The to field must contain either a socket address or a broadcast string. If it contains a socket address, the server will forward whatever you include in your payload string to that socket address (I will tell you how you get socket addresses from the server in a minute). If the to field contains a broadcast string, the server will forward whatever you include in your payload to every socket address but yours (this is what broadcast means).
The type field. This field exists for platform implementation. iOS clients use this field to determine what to do with each JSON object coming from the server. For example, when an iOS client receives a JSON object from the server of type 7, it knows it''s a response from a current chat session with another client, so it will consume whatever text is included in the payload field. In this example the type is 1, and for iOS clients this means essentially that a new client is connecting and broadcasting its profile information, included in the payload.
The payload field. This field contains whatever information you want to forward to a socket address. So again, in the previous JSON object I am broadcasting my first name, my photo in Base64, a brief message, and an enabled status.
Lastly, once the server has successfully parsed your JSON object, it will purge the payload from your JSON object and create a new JSON object that is forwarded to a specific socket address or to every socket address (broadcast), depending on what you requested in the to field. Using the previous JSON object as an example, the server will broadcast my first name, photo, etc. to every socket address. Suppose there is only 1 other connected socket address that exists as 111.222.333.0:444 (remember, the server maintains these addresses for all connected clients). The server will then create and send a new JSON object to 111.222.333.0:444 as:
"message": "I like iOS!",
Most of the code needs to be modified in AndroidClient.java. The code needs to connect to the server address of 126.96.36.199 port 1337. outputJSON contains the JSON that is needed to send details about your profile to the server. The method outputstrwr.write() is suppose to write that json string to the server. The images when received or sent need to converted to or converted from base 64 format. THE DATA SHOULD BE RECIEVED AND SENT IN BYTES NOT STRINGS.
The client uses the method getBytesFromInputStream() to receive bytes/profile data from the server. When the Android client receives json from the server is parses it the json it gets the base 64 string, profile name string, and tagline string to display in the listview by adding those strings to a hashmap in the refreshViewModels() method and it also converts the json string Profile objects using Google gson. The profile objects are stored in a hashmap called posMap. When the user clicks on a listview item it gets the profile from the posMap and calls the callProfileActivity() method which in turn sends the data to the ViewProfileActivity. This should display the profile details including the image which would require you to convert from base64 to bitmap. If there are any other questions please don''t be afraid to ask. The app needs to be test using two devices to make sure it works. For an example, device #1''s name is Ryan and device #2''s name is Paul, Ryan should show up in the listivew with the Name, Tagline, and Profile Pic on Paul''s device and Paul should show up in the listivew with the Name, Tagline, and Profile Pic on Ryan''s device.
Posted Date: 9/2/2012 2:27:54 AM | Location : United States
Ask an Expert
Android Development Project, Assignment Help, Ask Question on Android Development Project, Get Answer, Expert's Help, Android Development Project Discussions
Write discussion on Android Development Project
Your posts are moderated
Write your message here..
Padovan String, A Padovan string P(n) for a natural number n is defined as:...
A Padovan string P(n) for a natural number n is defined as: P(0)=''X'' P(1)=''Y'' P(2)=''Z'' for a string characters ''X'',''Y'',''Z'' only,and given value of n,write a program th
Explain primitive data types in java, Explain primitive data types in java?...
Explain primitive data types in java? Java's primitive data types are extremely similar to those of C. They involve boolean, byte, short, long, int, float, double, and char. Th
Java identifiers and variable class, 1. Which of the following are not vali...
1. Which of the following are not valid Java identifiers, and why? (a) wolVes (b) United(there is only one) (c) 87 (d) 5 3 (e) Real ale (f) isFound?by 2. A cla
Upload a file in struts? , In JSP page give the code as given below: en...
In JSP page give the code as given below: enctype="multipart/form-data" name="fileForm" scope="session"> Please select file here that you would like to upload:
What is an xml namespace?, Question 1 What is Response Redirection? Explai...
Question 1 What is Response Redirection? Explain in brief Question 2 What is JDBC? Explain Question 3 Write a short note on Expressions Question 4 What is an XML na
What should be public and private, What should be public? What should be pr...
What should be public? What should be private? As a rule of thumb: Classes are public. Fields are private. Constructors are public. Getter and setter methods
What is a final modifier? illustrate other java modifiers?, A final class w...
A final class will not be extended i.e. A final method cannot be overridden when its class is added. You can't modify value of a final variable.
Arrays, examples of 2D arrays
examples of 2D arrays
What is an aspect, An aspect is the cross-cutting functionality that you ar...
An aspect is the cross-cutting functionality that you are executing. It is the aspect of your application you are modularizing. An example of an aspect is logging. Logging is somet
Board Colourling, write a program to find the minimum no of colors to fill ...
write a program to find the minimum no of colors to fill a board where some of the elements of different color are already placed.
Accounting Assignment Help
Economics Assignment Help
Finance Assignment Help
Statistics Assignment Help
Physics Assignment Help
Chemistry Assignment Help
Math Assignment Help
Biology Assignment Help
English Assignment Help
Management Assignment Help
Engineering Assignment Help
Programming Assignment Help
Computer Science Assignment Help
IT Courses and Help
Why Us ?
~24x7 hrs Support
~Quality of Work
~Time on Delivery
~Privacy of Work
Human Resource Management
Literature Review Writing Help
Follow Us |
T & C
Copyright by ExpertsMind IT Educational Pvt. Ltd.