如何将Android手机连接到同一个Wi-Fi网络的电脑?
问题描述:
我是初学者Android开发者,我想使应用程序,可以从通过WiFi的Android设备播放流式视频,音乐和图片到电脑,这样我怎么能连接PC和Android这是同一个WiFi网络上? ,我的流媒体视频无需缓冲办?
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 ?
答
这code所示如何写code键使手机连接到PC。
你可以尝试从以下code开始。
This code is shown how to write the code to make the mobile connect to PC. You can try and start from following code.
/** 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
credit : gsmaker