I'm trying to get an example of running a WiFi peer-to-peer, where a user is the other The user can send the string. In, only files are sent - How can I send a string without the files and the stuff?
The code from the document:
Sending:
OutputStream output stream = socket.getOutputStream (); ContentResolver cr = context.getContentResolver (); InputStream inputstream = faucet; Inputstream = cr.openInputStream (Uri.parse ("path / to / picture.jpg")); While ((len = inputstream.read (buf))! = -1) {outputstream.write (buf, 0, len); } Outputstream.close (); InputStream.close ();
Getting:
last file f = new file (environment .getExternalStorage directory () + "/" + context .getPackageName () + "/ Wifip2pshared-" + System.currentTimeMillis () + ".jpg"); File diary = new file (f.getParent ()); If (! Dirs.exists ()) dirs.mkdirs (); F.createNewFile (); InputStream inputstream = client.getInputStream (); CopyFile (inputstream, new file-output stream (F)); ServerSocket.close (); Return f.getAbsolutePath ();
How do I need to modify the strings to send / receive this code? (Without file).
- Convert your
string
to a byte in yourOutputStream
String.getBytes ()
Comments
Post a Comment