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
Post a Comment