android udp demo
来源:互联网 发布:mac win7 编辑:程序博客网 时间:2024/06/05 20:38
public void sendUDPmsg(){
DatagramSocket sendSocket = null;
try {
sendSocket = new DatagramSocket(); } catch (SocketException e) { e.printStackTrace(); } String ServerIp = "114.55.89.143"; InetAddress ip = null; int port = 7777; try { ip = InetAddress.getByName(ServerIp); } catch (UnknownHostException e) { e.printStackTrace(); } byte[] bys = new byte[]{}; DatagramPacket sendPacket = new DatagramPacket(bys, bys.length, ip, port); try { sendSocket.send(sendPacket); } catch (IOException e) { e.printStackTrace(); } byte[] getBuf = new byte[256]; DatagramPacket getPacket = new DatagramPacket(getBuf, getBuf.length); try { sendSocket.setSoTimeout(4000); } catch (SocketException e) { e.printStackTrace(); } try { sendSocket.receive(getPacket); } catch (IOException e) { e.printStackTrace(); } StringBuffer bd = new StringBuffer(); for (int iu = 0; iu < getPacket.getLength(); iu++) { String hex = Integer.toHexString(getBuf[iu] & 0xFF) .toUpperCase(); if (hex.length() == 1) { hex = '0' + hex; } bd.append(hex); } String res = bd.toString(); System.out.println(res + "发送回复");}
0 0
- android udp demo
- Android UDP demo
- android udp demo
- Android下UDP通信DEMO
- UDP Demo
- udp--demo
- android学习日记——基于UDP的聊天demo
- Udp实现通信DEMO
- UDP Socket Demo 总结
- udp服务器端demo
- Netty UDP demo
- UDP 最简单DEMO
- STM32F4 LWIP UDP Demo
- udp连接通信demo
- java udp协议请求demo
- winsock实现UDP通信DEMO
- Android Socket专题:UDP通信客户端app的demo的实现
- Android Socket专题: UDP通信服务器端app的demo的实现
- webView中拿到选取的文字
- Redis安装
- 精通 CSS+DIV 网页样式与布局 155
- 工具 - gson解析json
- 计算G711语音的打包长度和RTP里timestamp(时间戳)的增长量
- android udp demo
- centos 7下rabbitmq集群搭建
- Android加载进度条 (仿ios)效果
- android APP检测版本更新以及后台服务更新
- prv
- 关于 Demo_Ocean 例子的分析
- 读了《沃兹传》后遗留的问题
- Bootstrap3 表单-调整列(column)尺寸
- Error connecting to server :致命错误 SSL关闭的pg_hba.conf记录