您的位置:首页 > 编程语言 > Python开发

简单的性能自动化测试架构设计和实现(pylot)-python

2014-04-16 22:06 761 查看
package test;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class UdpServer {
/*
* UDP服务端,监听本地端口:8200
*/
public static void main(String arg[])
{
try
{
InetSocketAddress socketAddress = null;
DatagramSocket ds = null;
byte[] buffer = new byte[1024];
DatagramPacket packet = null;

socketAddress = new InetSocketAddress("180.180.1.136",8200);
ds = new DatagramSocket(socketAddress);
while(true)
{
//接收数据
packet = new DatagramPacket(buffer, buffer.length);
ds.receive(packet);//阻塞进程
byte[] nBytes=packet.getData();
System.out.println(nBytes.toString());
//发送数据
DatagramPacket dp = new DatagramPacket(buffer, buffer.length, packet.getAddress(), packet.getPort());
dp.setData(nBytes);
ds.send(dp);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

该程序为UDP传输服务端,监听本地端口:绑定本地IP和端口8200

思路:

1.建立udpSocket服务(DatagramSocket)

2.提供数据,并将数据封装到数据包中(DatagramPacket)

3.通过socket服务(send)的发送功能,并将数据包发送出去

4.关闭资源
本文出自 “悠着点,慢着点” 博客,请务必保留此出处http://sdqdxiaoli.blog.51cto.com/6211128/1066205
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐