新浪旧事-Java向飞秋(FeiQ)发送消息
2012-04-13 09:24
363 查看
package test; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; import java.util.Date; public class TestFeiQ { public static void main(String[] args) { DatagramSocket socket; InetAddress address; long IPMSG_SENDMSG = 0x00000020; String SENDER = "乱 7 8 糟"; String HOST = "Localhost"; String MSG_CONTENT = "Hello 世界!"; try { socket = new DatagramSocket(); address = InetAddress.getByName("192.168.0.145");// 发送给消息的地址 byte[] buffer = ("1:" + new Date().getTime() + ":" + SENDER + ":" + HOST + ":" + IPMSG_SENDMSG + ":" + MSG_CONTENT) .getBytes("gbk"); DatagramPacket packet = new DatagramPacket(buffer, buffer.length, address, 2425); socket.send(packet); // 发送报文 packet = new DatagramPacket(buffer, buffer.length); socket.receive(packet);// 接收回应 String message = new String(packet.getData()); // 得到报文信息 System.out.println(message); // 显示对方返回的信息 } catch (UnknownHostException e) { e.printStackTrace(); } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- java向飞秋发送提示消息(转载预留,方法可以包装打成jar包用)
- Java 给飞秋发送消息
- JAVA实现飞秋发送报文消息
- 局域网 飞秋 java 发送消息
- Java 给飞秋发送消息
- Web Service学习笔记(webservice、soap、wsdl、jws详细分析) Webservice的wsdl文件解析与Soap消息的发送、接收(不生成java客户端代码)
- Webservice的wsdl文件解析与Soap消息的发送、接收(不生成java客户端代码)
- 使用Java语言开发微信公众平台(四)——图文消息的发送与响应
- 用Java向IPMSG发送消息
- Java模拟异步消息的发送与回调
- 微信&java 开发2 发送文本消息并回复
- java向linux的kafka发送消息 并接收消息实例
- 微信支付java版本之JSAPI支付+发送模板消息
- 用Java向IPMSG发送消息
- java微信开发(wechat4j)——发送客服消息
- Java监听和发送飞秋群消息
- 微信公共号开发教程java版——发送消息和处理消息(四)
- Java模拟web微x登录发送文字和图片消息简单实现爬虫
- python:使用udp协议发送飞秋消息
- Java 微信发送模板消息