home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-21 | 1.9 KB | 58 lines |
- package multi;
-
- import java.net.*;
- import java.io.*;
-
- public class sender extends Thread {
- public static void main(String[] args) throws UnknownHostException, SocketException {
- new SendThread(args);
- }
- }
-
- class SendThread extends Thread {
- InetAddress address;
- int port;
- ByteArrayOutputStream bout;
- DataOutputStream dout;
- DatagramSocket socket;
-
- public SendThread(String[] args)
- throws UnknownHostException, SocketException {
- address = InetAddress.getByName(args[0]);
- port = Integer.parseInt(args[1]);
- bout = new ByteArrayOutputStream();
- dout = new DataOutputStream(bout);
- socket = new DatagramSocket();
- start();
- }
-
- public void run() {
- int seq = 1;
- int timestamp = 140;
- while (true) {
- bout.reset();
- try {
- dout.writeByte(0x80); // version = 2, padding = 0, extension = 0, CSRC count = 0
- dout.writeByte(79); // mark = 0, payload type = 79
- dout.writeShort(seq++);
- dout.writeInt(timestamp); timestamp += 3;
- dout.writeInt(1724);
- dout.writeFloat(1f); dout.writeFloat(2f); dout.writeFloat(3f);
- dout.writeFloat(0f); dout.writeFloat(1f); dout.writeFloat(0f); dout.writeFloat(0);
- dout.writeInt(7); // region
- dout.writeFloat(2.75f); // size
- dout.writeShort(0); // flags
- DatagramPacket packet = new DatagramPacket(bout.toByteArray(),
- bout.size(), address, port);
- socket.send(packet);
- }
- catch (IOException e) {
- System.out.println("Cannot build/construct packet: " + e);
- break;
- }
- try { sleep(3000); }
- catch (InterruptedException e) { }
- }
- }
- }
-