⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vitralcommandclient.java

📁 基于java的3d开发库。对坐java3d的朋友有很大的帮助。
💻 JAVA
字号:
//===========================================================================// Java basic classesimport java.net.Socket;import java.io.InputStream;import java.io.OutputStream;// VitralSDK classesimport vsdk.toolkit.io.PersistenceElement;public class VitralCommandClient implements Runnable{    private SceneEditorApplication parent;    public boolean running;    private String ip;    private int port;    private Socket socket;    public VitralCommandClient(SceneEditorApplication parent, String ip, int port)    {        this.parent = parent;        this.ip = ip;        this.port = port;        socket = null;        running = true;    }    private void requestServiceTransaction(InputStream is,                                           OutputStream os)    {        String petition = "getCommand";        String msg;        byte responseType[] = new byte[1];        try {            PersistenceElement.writeAsciiString(os, petition);            PersistenceElement.readBytes(is, responseType);            if ( responseType[0] == 1 ) {                ; // Empty answer            }            else if ( responseType[0] == 5 ) {                msg = PersistenceElement.readAsciiString(is);                parent.externalCommand(msg);            }            else {                // ??                System.err.println("Warning: unsupported answer from server (" +responseType[0] + ").");                System.err.println("Closing connection.");                running = false;            }        }        catch ( Exception e ) {            System.err.println("Error in requestServiceTransaction.");            System.err.println("Closing connection.");            System.err.println(e);            running = false;        }    }    public void run()    {        System.out.println("Starting VitralCommandClient thread.");        System.out.println("Trying to connect to IP " + ip + " at port " + port + "... ");        InputStream is;        OutputStream os;        try {            socket = new Socket(ip, port);            is = socket.getInputStream();            os = socket.getOutputStream();        }        catch ( Exception e ) {            System.err.println("Error trying to connect.");            System.err.println("Check application has access to network and server side application is running!");            System.err.println(e);            return;        }        while ( running ) {            requestServiceTransaction(is, os);            try {                Thread.sleep(500);            }            catch ( Exception e ) {                ;            }        }        if ( socket != null ) {            try {                socket.close();            }            catch( Exception e ) {                ;            }            socket = null;        }        System.out.println("\nEnding VitralCommandClient thread.\n");    }    public void end()    {        if ( socket != null ) {            try {                socket.close();            }            catch( Exception e ) {                ;            }            socket = null;        }        running = false;    }}//===========================================================================//= EOF                                                                     =//===========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -