当前位置:   article > 正文

java实现UDP传输系统源码(附完整源码)_java udp通信编程源码

java udp通信编程源码

java实现UDP传输系统源码


以下是一个简单的Java UDP传输系统的完整源码:

UDPClient.java

import java.io.IOException;
import java.net.*;

public class UDPClient {
    public static void main(String[] args) throws IOException {
        DatagramSocket clientSocket = new DatagramSocket();
        InetAddress serverIP = InetAddress.getByName("localhost");
        byte[] sendData = "Hello, UDP Server".getBytes();
        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, serverIP, 9876);
        clientSocket.send(sendPacket);
        byte[] receiveData = new byte[1024];
        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
        clientSocket.receive(recei
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/146759?site
推荐阅读
相关标签
  

闽ICP备14008679号