File: customServerExample.java

package info (click to toggle)
libaria 2.8.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,628 kB
  • ctags: 16,574
  • sloc: cpp: 135,490; makefile: 925; python: 597; java: 570; ansic: 182
file content (57 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

import com.mobilerobots.Aria.*;
import com.mobilerobots.ArNetworking.*;

class RequestCallback extends ArFunctor_ServerData
{
  public void invoke(ArServerClient client, ArNetPacket packet)
  {
    ArNetPacket sending = new ArNetPacket();
    System.out.println("customServerExample: RequestCallback: responding to a request packet with ID " + packet.getCommand());
    client.sendPacketTcp(sending); // just send back an empty packet.
  }
}

public class customServerExample {


  /* This loads all the ArNetworking classes (they will be in the global
   * namespace) when this class is loaded: */
  static {
    try {
        System.loadLibrary("AriaJava");
        System.loadLibrary("ArNetworkingJava");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code libraries (AriaJava and ArNetworkingJava .so or .DLL) failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
      System.exit(1);
    }
  }


  public static void main(String[] argv)
  {
    Aria.init();
    ArServerBase server = new ArServerBase();
    ArNetPacket packet = new ArNetPacket(); // empty packet to test broadcasting

    RequestCallback testCB = new RequestCallback();

    server.addData("test", "some wierd test", testCB, "none", "none");
    server.addData("test2", "another wierd test", testCB, "none", "none");
    server.addData("test3", "yet another wierd test", testCB, "none", "none");
    if (!server.open(7273))
    {
      System.err.println("customServerExample: Could not open server port 7273");
      System.exit(1);
    }
    server.runAsync();
    System.out.println("customServerExample: ready for customClientExamples to connect on port 7273; will broadcast \"test3\" packet every 4 seconds as well.");
    while (server.getRunningWithLock())
    {
      ArUtil.sleep(4000);
      server.broadcastPacketTcp(packet, "test3");
    }
    Aria.shutdown();
  }
}