我正在编写代码,我想将 mp4 文件发送到另一台 Android 设备。我已经通过 Wifi 连接两个 Android,并从一个简单的循环中写入 1-20,另一个 Android 设备读取并显示发送的数字。
这是“发送者”的有趣部分:
InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
Log.d("ClientActivity", "C: Connecting...");
Socket socket = new Socket(serverAddr, port);
connected = true;
while (connected) {
try {
Log.d("ClientActivity", "C: Sending command.");
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket
.getOutputStream())), true);
for (int i = 1; i < 20; i++) {
out.println(i);
i=i++;
和“接收者”:
serverSocket = new ServerSocket(SERVERPORT);
// listen for incoming clients
Socket client = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()),8*1024);
这很好用!但我想将文件从一个设备发送到另一个设备而不是 int。我怎么能做这个??????