Sunday, January 26, 2014

Android development of similar micro-channel program


            
Want to develop on the Android platform, a similar micro-channel program, a server, the server will assign an IP address to the client when the client login, then you can send voice messages directly between two clients, no transmission of information through the server. How to achieve information transmission?
Reply:
Client server will assign an ip?

Reply:
The answer - the teachers beg the landlord arranged graduation. . . . No clue
Reply:
LZ ah this is p2p communications technology through the wall, a little hard, you can go to understand,
Reply:
That also what server ah.
        

Reply:
It is up to the server doing? Open a recording function, generate a mp3, direct the MMS.
Reply:
reference to the third floor huangzuduan reply:
LZ This is p2p communications technology through the wall ah, a bit difficult, you can get to know the next,


socket can do
Reply:
references, 5th Floor hjywyj reply:
it to the server doing? Open a recording function, generate a mp3, direct the MMS.


Server to dynamically assign IP
Reply:
cited a floor wjw2066616 reply:
client server will assign an ip?


Yes
Reply:
P2P technology. PCM signal does it send compressed iLBC
Reply:
reference to the 9th floor tom96202 reply:
P2P technology. ILBC compressed PCM signals are not sent it

Uh, you say ah well advanced, I think recording and socket communication to send it on the line, can specifically talk about it
Reply:
The server to the client assigned IP? I think my network is a white school, and that the routing layer is IP server is doing ...... ......
who assigned
------------------------- ----------------------------- AutoCSDN Signature -------------------- ----------------------------------
yard farm - yard farmers sow code grazing thinking farm.

Reply:

ip is not assigned to a server, you can use the socket when customers log or use servlet. Communication between the client can use udp (datagramsocket)
Reply:
reference to the 11th floor hankcs reply:
server to the client assigned IP? I think my network is a white school, and that the routing layer is IP server is doing ...... ......
who assigned
------------------------- ----------------------------- AutoCSDN Signature -------------------- ----------------------------------
yard farm - yard farmers sow code grazing thinking farm.

The teacher said so, I do not know ah, the server is our own doing, Ann a wifi, build a database, and then blabla
Reply:
reference to the 12th floor aaaabbbccd9876 reply:

ip is not assigned to a server, you can use the socket when customers log or use servlet. Communication between the client can use udp (datagramsocket)

There are examples of wood ah, do not laugh at it it fun ah
Reply:
reference to the 14th floor u011562884 reply:
Quote: references to the 12th floor aaaabbbccd9876 reply:


ip is not assigned to a server, you can use the socket when customers log or use servlet. Communication between the client can use udp (datagramsocket)

There are examples of wood ah, do not laugh at it it happy ah
previously wrote, because there is no order, no more
Reply:
reference to the 8th floor u011562884 reply:
Quote: references to a floor wjw2066616 reply:

Client server will assign an ip?


Yes

I'm going to tell you is how it should be you misheard or misunderstood. . . . Not a server to dynamically allocated ip. . The client communicates with the server is client-server ip you can get the full use UDP to communicate. What is the graduation project. . UDP enough. . Your client only when the server using a socket to get your client's ip after telling other clients. . Then be able to communicate the (this is the case outside the local area network to be slightly more complex) between them. . . Or by forwarding the message to the server is also possible
Reply:
IP is not fixed it
Reply:
Our course work, I wrote a similar QQ chat program such, if you want to you
Reply:
cited 18 floor jiangxiaoma111 reply:
our course work, I wrote a similar QQ chat program like this, if you want to you


Great, you sent to my mailbox, thank you wrh77@foxmail.com
Reply:
reference to the 16th floor wjw2066616 reply:
Quote: references to the 8th floor u011562884 reply:

Quote: references to a floor wjw2066616 reply:

Client server will assign an ip?


Yes

I'm going to tell you is how it should be you misheard or misunderstood. . . . Not a server to dynamically allocated ip. . The client communicates with the server is client-server ip you can get the full use UDP to communicate. What is the graduation project. . UDP enough. . Your client only when the server using a socket to get your client's ip after telling other clients. . Then be able to communicate the (this is the case outside the local area network to be slightly more complex) between them. . . Or rely on servers to forward messages is also possible


Ah, ip that is indeed my understanding is wrong, the teacher said later let the client put together IP and user name to the server, then the server into the database, so that when the user name search by another client, server, put the corresponding ip issued to him. Communication between the two phones, I wanted to let each other socket server and client, do you think it possible, do not get socket server on Android
Reply:
cited landlord u011562884 reply:
want to develop on the Android platform, a similar micro-channel program, a server, a client server will log the client is assigned an IP address and can be sent directly to the voice information between the two clients, the information is not transmitted through the server. How to achieve information transmission?

Oh feeling a bit chaotic
logicTwo clients is how to connect? Server with a substantially
Reply:
cited 21 floor qiuqingpo reply:
Quote: references landlord u011562884 reply:

Want to develop on the Android platform, a similar micro-channel program, a server, the server will assign an IP address to the client when the client login, then you can send voice messages directly between two clients, no transmission of information through the server. How to achieve information transmission?

Oh feeling a bit chaotic
logicTwo clients is how to connect? Server is basically useless

Meaning of the landlord should be, both A and B clients to connect to the server. The server then records the IP address of both the client and the IP address A to B, IP address B to A, and between these two clients as one of the server (assumed to be A), then the other party IP addresses can be used to connect A up. Message passing between them can directly point to point, and no longer need to transit through the server.
I do not know understanding correct?
Reply:
cited 22 floor jiangxiaoma111 reply:
Quote: references 21 F qiuqingpo reply:

Quote: references landlord u011562884 reply:

Want to develop on the Android platform, a similar micro-channel program, a server, the server will assign an IP address to the client when the client login, then you can send voice messages directly between two clients, no transmission of information through the server. How to achieve information transmission?

Oh feeling a bit chaotic
logicTwo clients is how to connect? Server is basically useless

Meaning of the landlord should be, both A and B clients to connect to the server. The server then records the IP address of both the client and the IP address A to B, IP address B to A, and between these two clients as one of the server (assumed to be A), then the other party IP addresses can be used to connect A up. Message passing between them can directly point to point, and no longer need to transit through the server.
I do not know understanding correct?


Too right, that's it, but how do point
Reply:
cited 23 floor u011562884 reply:
Quote: references 22 F jiangxiaoma111 reply:

Quote: Quote Reply 21 F qiuqingpo of:

Quote: references landlord u011562884 reply:

Want to develop on the Android platform, a similar micro-channel program, a server, the server will assign an IP address to the client when the client login, then you can send voice messages directly between two clients, no transmission of information through the server. How to achieve information transmission?

Oh feeling a bit chaotic
logicTwo clients is how to connect? Server is basically useless

Meaning of the landlord should be, both A and B clients to connect to the server. The server then records the IP address of both the client and the IP address A to B, IP address B to A, and between these two clients as one of the server (assumed to be A), then the other party IP addresses can be used to connect A up. Message passing between them can directly point to point, and no longer need to transit through the server.
I do not know understanding correct?


Too right, that's it, but how do point


Then write a server-side code according to write a similar, equivalent to the phone either as a server and a client such as mobile phone client.
Reply:
There are open source messaging server openfire landlord can look
Reply:
reference to the 24th floor jiangxiaoma111 reply:
Quote: references 23 F u011562884 reply:

Quote: references 22 F jiangxiaoma111 reply:

Quote: Quote Reply 21 F qiuqingpo of:

Quote: references landlord u011562884 reply:

Want to develop on the Android platform, a similar micro-channel program, a server, the server will assign an IP address to the client when the client login, then you can send voice messages directly between two clients, no transmission of information through the server. How to achieve information transmission?

Oh feeling a bit chaotic
logicTwo clients is how to connect? Server is basically useless

Meaning of the landlord should be, both A and B clients to connect to the server. The server then records the IP address of both the client and the IP address A to B, IP address B to A, and between these two clients as one of the server (assumed to be A), then the other party IP addresses can be used to connect A up. Message passing between them can directly point to point, and no longer need to transit through the server.
I do not know understanding correct?


Too right, that's it, but how do point


Then write a server-side code according to write a similar, equivalent to the phone either as a server and a client such as mobile phone client.


Now is written, but there are always exceptions, can not be used
Reply:
Look at the whole thing out of the exception code
Reply:
reference to the 27th floor sybell reply:
look at the whole thing out of the exception code


package com.example.map2;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.List;

import org.apache.http.conn.util.InetAddressUtils;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class Communication extends Activity {
private Button bt, btback, btadd;
private TextView tv;
private Socket socket;
private String serverIpAddress;
private ListView mListView;

private ChatMsgViewAdapterRight mAdapterright;
private ChatMsgViewAdapterLeft mAdapterleft;
private EditText et;
private List mDataArrays = new ArrayList ();
LayoutInflater mLayoutInflater = null;

private static final int REDIRECTED_SERVERPORT = 6000;

public void onCreate (Bundle savedInstanceState) {

super.onCreate (savedInstanceState);
setContentView (R.layout.comunication);
mLayoutInflater = LayoutInflater.from (this);
/ / Start the activity does not pop up automatically when the soft keyboard
getWindow () setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);.

bt = (Button) findViewById (R.id.btn_send);
btback = (Button) findViewById (R.id.communicate_back_btn);
btadd = (Button) findViewById (R.id.add_btn2);
tv = (TextView) findViewById (R.id.myTextView);
mListView = (ListView) findViewById (R.id.listview);
et = (EditText) findViewById (R.id.et_sendmessage);
serverIpAddress = getLocalIpAddress ();

new Thread (new Runnable () {
public void run () {

try {
ServerSocket server = new ServerSocket (REDIRECTED_SERVERPORT) ;/ / listening on that port
while (true)
{
Socket client = server.accept () ;/ / accept client requests
InputStream is = client.getInputStream ();
OutputStream os = client.getOutputStream ();
DataInputStream dis = new DataInputStream (is);
String request = dis.readLine ();
PrintStream out = new PrintStream (os) ;/ / obtain client output stream
out.print (request);
client.close ();
server.close ();
}

} Catch (UnknownHostException e) {
tv.setText ("ServerError1:" + e);
e.printStackTrace ();
} Catch (IOException e) {
tv.setText ("ServerError2:" + e);
e.printStackTrace ();
} Catch (Exception e) {
tv.setText ("ServerError3:" + e);
e.printStackTrace ();
}
handler.sendEmptyMessage (0);
}
.}) Start ();

bt.setOnClickListener (new OnClickListener () {

public void onClick (View v) {
new Thread (new Runnable () {
public void run () {
String str = et.getText () toString ();.
if (str.length ()> 0)
{


try {
ChatMsgEntity entity = new ChatMsgEntity ();
entity.setDate (getDate ());
entity.setName ("I");
entity.setMsgType (false);
entity.setText (str);
mDataArrays.add (entity);
mAdapterright.notifyDataSetChanged ();
et.setText ("");
mListView.setSelection (mListView.getCount () - 1);

InetAddress serverAddr = InetAddress.getByName (serverIpAddress);
socket = new Socket (serverAddr, REDIRECTED_SERVERPORT) ;/ / create a connection to each IP, 6000 port numbers socket
InputStream is = socket.getInputStream ();
OutputStream os = socket.getOutputStream ();
PrintStream out = new PrintStream (os);
out.println (str);
DataInputStream dis = new DataInputStream (is);
String request = dis.readLine ();
ChatMsgEntity entity2 = new ChatMsgEntity ();
entity2.setDate (getDate ());
entity2.setName ("Friends");
entity2.setMsgType (false);
entity2.setText (request);
mDataArrays.add (entity2);
mAdapterleft.notifyDataSetChanged ();
mListView.setSelection (mListView.getCount () - 1);
socket.close ();
/ / Log.d ("Client", "Client sent message");
} Catch (UnknownHostException e) {
tv.setText ("Error1:" + e);
e.printStackTrace ();
} Catch (IOException e) {
tv.setText ("Error2:" + e);
e.printStackTrace ();
} Catch (Exception e) {
tv.setText ("Error3:" + e);
e.printStackTrace ();
}
}
handler.sendEmptyMessage (0);
}

.}) Start ();
}
});


btback.setOnClickListener (new OnClickListener () {
public void onClick (View v) {
finish ();
}
});
btadd.setOnClickListener (new OnClickListener () {
public void onClick (View v) {
finish ();
}
});
}
private String getDate () {
Calendar c = Calendar.getInstance ();

String year = String.valueOf (c.get (Calendar.YEAR));
String month = String.valueOf (c.get (Calendar.MONTH));
String day = String.valueOf (c.get (Calendar.DAY_OF_MONTH) + 1);
String hour = String.valueOf (c.get (Calendar.HOUR_OF_DAY));
String mins = String.valueOf (c.get (Calendar.MINUTE));

StringBuffer sbBuffer = new StringBuffer ();
sbBuffer.append (year + "-" + month + "-" + day + "" + hour + ":" + mins);

return sbBuffer.toString ();
}

public static String getLocalIpAddress () {

try {
for (Enumeration en = NetworkInterface.getNetworkInterfaces (); en.hasMoreElements () ;) {
NetworkInterface intf = en.nextElement ();
for (Enumeration enumIpAddr = intf
. GetInetAddresses (); enumIpAddr.hasMoreElements () ;) {
InetAddress inetAddress = enumIpAddr.nextElement ();
if (! inetAddress.isLoopbackAddress () && InetAddressUtils.isIPv4Address (inetAddress.getHostAddress ())) {

return inetAddress.getHostAddress () toString ();.
}
}
}
} Catch (SocketException e) {
/ / TODO: handle exception

}

return null;
}
/ / Define the Handler object
private Handler handler = new Handler () {
@ Override
/ / When the message is sent out when there is this method of implementation
Handlerpublic void handleMessage (Message msg) {
super.handleMessage (msg);
/ / Handle UI
}
};
}

Reply:
Help us to see it, or the great God who help write, pointing pointing, coming time, grateful ah
Reply:
If you do not depend on the server, terminal communication service to do both ends, but also as a client. Between the use of socket communications.
Reply:
reference to the 30th floor shaojieli reply:
If you do not depend on the server, terminal communication service to do both ends, but also as a client. Between the use of socket communications.


Ah really think so, in the same application in both client-side code, another server code, and the contents are displayed in the same interface, you help me to write about it, it is necessary to use threads
Reply:
cited 31 floor u011562884 reply:
Quote: references to the 30th floor shaojieli reply:

If you do not depend on the server, terminal communication service to do both ends, but also as a client. Between the use of socket communications.


Ah really think so, in the same application in both client-side code, another server code, and the contents displayed on the same screen, can you help me to write about it, it is necessary to use the thread

Even if you do a normal chat program, it also used the thread
Reply:
reference to the 8th floor u011562884 reply:
Quote: references to a floor wjw2066616 reply:

Client server will assign an ip?


Yes


IP is the most basic things are not clear yet what the development Gesha ah? ? ?
Reply:
Direct socket

No comments:

Post a Comment