<p>Can you provide an example of a byte buffer transferred between two java classes via UDP datagram?</p>

[{'answer_id': 80071, 'author': 'Dave Cheney', 'author_id': 6449, 'author_profile': 'https://Stackoverflow.com/users/6449', 'pm_score': 3, 'selected': True, 'text': '<p>Hows\' this ?</p>\n\n<pre>\nimport java.io.IOException;\nimport java.net.DatagramPacket;\nimport java.net.DatagramSocket;\nimport java.net.InetSocketAddress;\n\n\npublic class Server {\n\n    public static void main(String[] args) throws IOException {\n        DatagramSocket socket = new DatagramSocket(new InetSocketAddress(5000));\n        byte[] message = new byte[512];\n        DatagramPacket packet = new DatagramPacket(message, message.length);\n        socket.receive(packet);\n        System.out.println(new String(packet.getData(), packet.getOffset(), packet.getLength()));\n    }\n}\n</pre>\n\n<pre>\nimport java.io.IOException;\nimport java.net.DatagramPacket;\nimport java.net.DatagramSocket;\nimport java.net.InetSocketAddress;\n\n\npublic class Client {\n\n    public static void main(String[] args) throws IOException {\n        DatagramSocket socket = new DatagramSocket();\n        socket.connect(new InetSocketAddress(5000));\n        byte[] message = "Oh Hai!".getBytes();\n        DatagramPacket packet = new DatagramPacket(message, message.length);\n        socket.send(packet);\n    }\n}\n</pre>\n'}, {'answer_id': 80139, 'author': 'Dave Cheney', 'author_id': 6449, 'author_profile': 'https://Stackoverflow.com/users/6449', 'pm_score': 0, 'selected': False, 'text': '<p>@none</p>\n\n<p>The DatagramSocket classes sure need a polish up, DatagramChannel is slightly better for clients, but confusing for server programming. For example:</p>\n\n<pre>\nimport java.io.IOException;\nimport java.net.InetSocketAddress;\nimport java.nio.ByteBuffer;\nimport java.nio.channels.DatagramChannel;\n\n\npublic class Client {\n\n    public static void main(String[] args) throws IOException {\n        DatagramChannel channel = DatagramChannel.open();\n        ByteBuffer buffer = ByteBuffer.wrap("Oh Hai!".getBytes());\n        channel.send(buffer, new InetSocketAddress("localhost", 5000));\n    }\n}\n</pre>\n\n<p>Bring on <a href="http://jcp.org/en/jsr/detail?id=203" rel="nofollow noreferrer" title="JSR-203">JSR-203</a> I say</p>\n'}]
['https://Stackoverflow.com/questions/80042', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']