한 사용자가 다른 사용자에게 간단한 문자열을 보낼 수있는 WiFi 피어 - 투 - 피어에 대한 실행 예제를 얻으려고합니다. example in the documentation에서 파일 만 전송됩니다 - 어떻게 파일 및 항목없이 문자열을 보낼 수 있습니까? 문서에서WiFi를 통해 파일 대신 간단한 문자열 보내기 P2P
코드 :
가 송신 :
OutputStream outputStream = socket.getOutputStream();
ContentResolver cr = context.getContentResolver();
InputStream inputStream = null;
inputStream = cr.openInputStream(Uri.parse("path/to/picture.jpg"));
while ((len = inputStream.read(buf)) != -1) {
outputStream.write(buf, 0, len);
}
outputStream.close();
inputStream.close();
수신 : I 보내기이 코드를 수정해야 할 것입니다 방법
final File f = new File(Environment.getExternalStorageDirectory() + "/"
+ context.getPackageName() + "/wifip2pshared-" + System.currentTimeMillis()
+ ".jpg");
File dirs = new File(f.getParent());
if (!dirs.exists())
dirs.mkdirs();
f.createNewFile();
InputStream inputstream = client.getInputStream();
copyFile(inputstream, new FileOutputStream(f));
serverSocket.close();
return f.getAbsolutePath();
/문자열을 수신? (파일 없음).