added gitignore
[clientserver.git] / TestServer.java
blobb4222d65ed97d848762bbe2b6f352ccae11104ed
1 /*
2 * @(#)TestServer.java
3 * Time-stamp: "2007-09-18 10:48:44 anton"
4 */
6 import java.net.DatagramPacket;
7 import java.net.InetAddress;
8 import java.net.DatagramSocket;
10 /**
11 * TestServer
13 * @author "Anton Johansson" <anton.johansson@gmail.com>
15 public class TestServer {
16 public TestServer() {
19 public static void main (String argv[]) throws Exception
21 // Skapa socket
22 DatagramSocket clientSocket = new DatagramSocket();
23 // Skapa IP-adress
24 InetAddress IPAddress = InetAddress.getByName("localhost");
25 // Läs in från tangentbordet
26 byte[] sendData = new byte[1024];
27 String message = "hej detta er meddelandet";
28 sendData[0] = (byte) 2;
29 sendData[1] = new Integer(message.length()).byteValue();
30 for (int i = 0, n = message.length(); i < n; i++) {
31 sendData[i+2] = (byte) message.charAt(i);
34 System.out.println("length -> " + sendData[1]);
35 // Skapa datagram med sänddata och sänd det
36 DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 7877);
37 clientSocket.send(sendPacket);
39 clientSocket.close();