Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created with IntelliJ IDEA.
- * User: e.suvorov
- * Date: 15.04.13
- * Time: 15:29
- * To change this template use File | Settings | File Templates.
- */
- import java.io.ByteArrayInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.*;
- import java.awt.*;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- public class Ch24Test {
- public void run() throws Exception {
- DatagramSocket s = new DatagramSocket(24130);
- byte[] tosend = { '\n' };
- s.send(new DatagramPacket(tosend, 0, tosend.length, InetAddress.getByName("ch24.org"), 24130));
- JFrame fr = new JFrame("received");
- JLabel lbl = new JLabel();
- fr.add(lbl);
- fr.setVisible(true);
- fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- for (;;) {
- final int BUFSZ = 100 * 1024;
- byte[] torecv = new byte[BUFSZ];
- DatagramPacket recv = new DatagramPacket(torecv, torecv.length);
- s.receive(recv);
- System.out.println("RECEIVED: " + recv.getAddress());
- InputStream str = new ByteArrayInputStream(recv.getData());
- Image img = ImageIO.read(str);
- lbl.setIcon(new ImageIcon(img));
- fr.pack();
- }
- }
- public static void main(String[] args) {
- try {
- new Ch24Test().run();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
- }
Add Comment
Please, Sign In to add comment