Sending ByteArray using Java Sockets (Android programming) -


i have java code sends string socket. can use same code android.

public class gpcsocket {      private socket socket;      private static final int serverport = 9999;     private static final string server_ip = "10.0.1.4";      public void run() {         new thread(new clientthread()).start();     }      public int send(string str) {         try {             printwriter out = new printwriter(new bufferedwriter(                     new outputstreamwriter(socket.getoutputstream())),                     true);             out.println(str);             out.flush();         } catch (unknownhostexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         } catch (exception e) {             e.printstacktrace();         }         return str.length();     }      class clientthread implements runnable {         @override         public void run() {             try {                 inetaddress serveraddr = inetaddress.getbyname(server_ip);                 socket = new socket(serveraddr, serverport);             } catch (unknownhostexception e1) {                 e1.printstacktrace();             } catch (ioexception e1) {                 e1.printstacktrace();             }         }     } } 

now, need send binary information encoded in bytearray. might best ways this? i'm considering converting bytearray string use same method, guess 1 can send byte array information directly using java sockets.

just call write(byte[] a) on outputstream 1 socket.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -