字节数组问题

时间:2019-05-22 02:31:54

标签: java

我有一个UPD客户端套接字,在我看来,所有内容看起来都是正确的,但是由于某种原因,我在此行遇到了异常错误

[2, 60, 30, 40]

   c    date
0  1  [1, 2]
1  2     [3]
2  3     [0]
3  4     132

在这里,我的密码

byte [] m = args[0].getBytes();

公共类Server1 {     公共静态void main(String args []){

DatagramSocket aSocket = null;

try {

    //Create a UDP socket
    aSocket = new DatagramSocket();    
    byte [] m = args[0].getBytes();
    InetAddress aHost = InetAddress.getByName("localhost");
    int serverPort = 6789;                                                       

    DatagramPacket request =
    new DatagramPacket(m,  args[0].length(), aHost, serverPort);
    aSocket.send(request);                                  

    //Prepare a buffer of enough size
    byte[] buffer = new byte[100];
    DatagramPacket reply = new DatagramPacket(buffer, buffer.length);   

    //Waiting for response
    aSocket.receive(reply);

    //Display the resolution of the domain name
    System.out.println("Server Response" + ": " + new String(reply.getData(), 0, reply.getLength()));   

}catch (SocketException e){
    System.out.println("Socket: " + e.getMessage());

}catch (IOException e){
    System.out.println("IO: "+e.getMessage());

}finally {
    if(aSocket != null){
        aSocket.close();
    }
}   

}

0 个答案:

没有答案