使用UDP/TCP协议,写一个数据收发程序,能统计RTT时间,数据报丢失和重发次数。

本文档详细介绍了如何编写UDP和TCP协议的数据收发程序,包括UDP客户端和服务器,以及TCP客户端和服务器。同时,该程序具备统计往返时延(RTT)、数据报丢失和重传次数的功能,对于理解网络协议的性能分析具有实践价值。
摘要由CSDN通过智能技术生成
UDP
  1. UDP client
class UDPClient {
public static void main(String args[]) throws Exception
{
    //create input stream
    BufferedReader inFromUser =
    new BufferedReader(new InputStreamReader(System.in));
    //create client socket
    DatagramSocket clientSocket = new DatagramSocket();
    //get the host IP address using DNS
    InetAddress IPAddress = InetAddress.getByName(null);
    byte[] sendData = new byte[1024];
    String ack="";
    String sentence = inFromUser.readLine();
    int n=sentence.length();
    int loss=0;
    //get the time when the client sends request
    long startTime=System.nanoTime();
    //create datagram with date-to-send, length, IP address, port
    //segment the data into several packets.
    //each packet contain one byte.
    for(int i=0;i<n;i++){
        //each datagram includes a sequence number i
        String send=i+" "+ sentence.substring(i,i+1);
        sendData = send.getBytes();
        
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值