I am beginner android developer ,I want to make app that can stream video,music and picture to PC from android device over WiFi , so How can i connect PC and android which are on same WiFi network? , what i do for streaming video without buffering ?
问问题
4342 次
1 回答
1
此代码展示了如何编写代码以使移动设备连接到 PC。您可以尝试从以下代码开始。
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initControls();
String sentence = "TCP Test #1n";
String modifiedSentence;
try {
Socket clientSocket = new Socket("192.168.18.116", 8080);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
printScr("TCP Connected.");
outToServer.writeBytes(sentence + 'n');
modifiedSentence = inFromServer.readLine();
printScr(modifiedSentence);
printScr("TCP Success !!!");
clientSocket.close();
} catch (Exception e) {
printScr("TCP Error: " + e.toString());
}
}
private void initControls()
{
txtSendStatus = (TextView)findViewById(R.id.txtSendStatus);
}
public static void printScr(String message)
{
txtSendStatus.append( "n" + message );
}
信用:gsmaker
于 2013-03-31T22:08:04.570 回答