Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void sendTCP(byte[] data) {
- threadTCP = new Thread("Send TCP") {
- public void run() {
- Socket socketSendTCP = null;
- try {
- socketSendTCP = new Socket(address, port);
- } catch (UnknownHostException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- OutputStream os = null;
- try {
- os = socketSendTCP.getOutputStream();
- } catch (IOException e) {
- e.printStackTrace();
- }
- OutputStreamWriter osw = new OutputStreamWriter(os);
- BufferedWriter bw = new BufferedWriter(osw);
- DataOutputStream dos = new DataOutputStream(os);
- try {
- bw.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- try {
- dos.writeInt(data.length);
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (data.length > 0) {
- try {
- dos.write(data, 0, data.length);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- try {
- socketSendTCP.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement