Class CameraServer

java.lang.Object
com.ccc.barcode.CameraServer
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
QueueCameraServer

public class CameraServer extends Object implements Runnable
This server will pull in images and barcodes from all cameras configured in client mode. Below is a simple server for displaying barcodes from scans.
 
 public class BarcodePrintCameraServer extends CameraServer {
	
   public BarcodePrintCameraServer(InetSocketAddress address, ConnectionList connectionList) throws IOException {
	super(address);
   }

   @Override
   protected void onMessage(CameraConnection connection, CameraScanResult result) {
	System.out.println(result.getBarcode());
   }
 }
 
 
It's also easy to save images. Below is a server that saves scan images to a temporary directory as bitmap files.
 
 public class ImageSaveCameraServer extends CameraServer {
   private Path targetDirectory;
	
   public ImageSaveCameraServer(InetSocketAddress address, ConnectionList connectionList) throws IOException {
	super(address);
	targetDirectory = Files.createTempDirectory("barcode-sink");
   }

   @Override
   protected void onMessage(CameraConnection connection, CameraScanResult result) {
	try {
	    Path target = Files.createTempFile(targetDirectory, null, ".bmp");
	    String writerName = "BMP";
	    boolean isWriter = ImageIO.write(result.getImage(), writerName, target.toFile());
	    if (!isWriter) {
		System.out.println("Could not use writer: " + writerName);
		return;
	    }
	    System.out.println("Saved image to file: " + target);
	} catch (IOException e) {
	    System.out.println("Could not print file: " + e);
	}
   }
 }
 
 
  • Field Details

  • Constructor Details

    • CameraServer

      public CameraServer(InetSocketAddress address)
      Construct a server that will listen on the given address.
  • Method Details

    • onConnect

      protected void onConnect(CameraInfo connection)
      Called every time a new camera connects.
      Parameters:
      connection - Information on the camera.
    • onDisconnect

      protected void onDisconnect(CameraInfo connection)
      Called every time a camera disconnects.
      Parameters:
      connection - Information on the camera.
    • onMessage

      protected void onMessage(CameraInfo connection, CameraScanResult result)
      Called every time a camera receives a message.
      Parameters:
      connection - Information on the camera.
      result - Information from the scan.
    • run

      public void run()
      Starts the server. This can be called directly, but a developer can run it in the background as a thread.
       
       // Listen for camera on port 8080.
       Thread cameraServerThread = new Thread(new CameraServer(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 8080)));
       cameraServerThread.start();
       
       
      Specified by:
      run in interface Runnable