Guest User

Untitled

a guest
Jul 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. package cn.isccn.familycloudtv.activity;
  2.  
  3. import android.os.Bundle;
  4. import android.support.annotation.Nullable;
  5. import android.view.View;
  6.  
  7. import com.google.gson.FieldNamingPolicy;
  8. import com.google.gson.Gson;
  9. import com.google.gson.GsonBuilder;
  10.  
  11. import java.net.InetSocketAddress;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14.  
  15. import cn.isccn.familycloudtv.R;
  16. import cn.isccn.familycloudtv.bean.Packet;
  17. import cn.isccn.familycloudtv.network.UDPClient;
  18. import cn.isccn.familycloudtv.network.UDPClientHandler;
  19. import cn.isccn.familycloudtv.utils.MsgValue;
  20. import cn.isccn.familycloudtv.utils.SocketUtils;
  21. import cn.isccn.familycloudtv.utils.Utils;
  22.  
  23. /**
  24. * Create by hongxin.wen on 2018/7/6
  25. * <p>
  26. * 修改记录:
  27. * DES: 2018/7/6 V1.0 test by hongxin.wen
  28. */
  29. public class Test extends BaseActivity implements View.OnClickListener {
  30. private String json;
  31.  
  32.  
  33. @Override
  34. protected void onCreate(@Nullable Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. setContentView(R.layout.activity_test);
  37. findViewById(R.id.btn_test_conn).setOnClickListener(this);
  38. findViewById(R.id.btn_test_send).setOnClickListener(this);
  39. }
  40.  
  41. @Override
  42. public void onBackPressed() {
  43. super.onBackPressed();
  44. }
  45.  
  46. @Override
  47. public void onClick(View v) {
  48. if (v.getId() == R.id.btn_test_conn) {
  49. Packet packet = new Packet();
  50. // packet.setDevice_type(MsgValue.DEVICE_MOBILE);
  51. packet.setDevice_type(MsgValue.DEVICE_TV);
  52.  
  53. packet.setMsg_version("1.0");
  54.  
  55. /*packet.setMsg_type(MsgValue.MSG_USER);
  56. packet.setMsg_command(MsgValue.COMMAND_ADD);
  57. Packet.UserInfo userInfo = new Packet.UserInfo();
  58. userInfo.setUser_deviceid("a012345678");
  59. userInfo.setUser_id("123456");
  60. userInfo.setUser_pwd("123456");
  61. userInfo.setUser_status(MsgValue.STATUS_ONLINE);
  62. packet.setUser_info(userInfo);*/
  63.  
  64. packet.setMsg_type(MsgValue.MSG_FILE);
  65. packet.setMsg_command(MsgValue.COMMAND_UPLOAD);
  66. List<Packet.FileInfo> list = new ArrayList<>();
  67. Packet.FileInfo fileInfo = new Packet.FileInfo();
  68. fileInfo.setFile_name("00.txt");
  69. fileInfo.setModify_date("20180712");
  70. fileInfo.setFile_path("/ss/");
  71. fileInfo.setFile_size("21");
  72. fileInfo.setFile_type("file");
  73. list.add(fileInfo);
  74. packet.setFile_lists(list);
  75.  
  76. /*packet.setMsg_type(MsgValue.MSG_VIDEO);
  77. packet.setMsg_command(MsgValue.COMMAND_VIDEO);
  78. List<Packet.VideoInfo> videoLists = new ArrayList<Packet.VideoInfo>();
  79. Packet.VideoInfo videoInfo = new Packet.VideoInfo();
  80. videoInfo.setCam_id("1010210");
  81. videoInfo.setCam_pwd("qwer");
  82. videoInfo.setCam_ip("172.16.10.87");
  83. videoInfo.setCam_port("1080");
  84. videoInfo.setCam_name("相机1");
  85. videoInfo.setCam_remark("客厅");
  86. videoLists.add(videoInfo);
  87. packet.setVideoLists(videoLists);*/
  88.  
  89. Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
  90. json = gson.toJson(packet);
  91. new UDPClient(SocketUtils.HOSTNAME, SocketUtils.PORT).run();
  92. new Thread(new Runnable() {
  93. @Override
  94. public void run() {
  95. int i = 1;
  96. while (i > 0) {
  97. try {
  98. Thread.sleep(2000);
  99. UDPClientHandler.sendMsg(json, new InetSocketAddress(SocketUtils.HOSTNAME, SocketUtils.PORT));
  100. Utils.printLog("send json = " + json);
  101.  
  102. } catch (InterruptedException e) {
  103. e.printStackTrace();
  104. }
  105. i--;
  106. }
  107. }
  108. }).start();
  109.  
  110. } else if (v.getId() == R.id.btn_test_send) {
  111. }
  112. }
  113. }
Add Comment
Please, Sign In to add comment