• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Network类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.jme3.network.Network的典型用法代码示例。如果您正苦于以下问题:Java Network类的具体用法?Java Network怎么用?Java Network使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Network类属于com.jme3.network包,在下文中一共展示了Network类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: simpleInitApp

import com.jme3.network.Network; //导入依赖的package包/类
/**
 * Initialise the game.
 * @see SimpleApplication#simpleInitApp()
 */
@Override
public void simpleInitApp() {
  try {
    client = Network.connectToServer(host, port);
    client.start();
    new ClientNetListener(this, client);
  } catch (IOException e) {
    // TODO: Handle this exception.
    System.err.println("Error connecting to server.");
  }

  this.flyCam.setEnabled(false);
  waitingState = new WaitingState();
  stateManager.attach(waitingState);
}
 
开发者ID:meoblast001,项目名称:seally-racing,代码行数:20,代码来源:ClientApplication.java


示例2: main

import com.jme3.network.Network; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException{
    Logger.getLogger("").getHandlers()[0].setLevel(Level.OFF);
    
    Server server = Network.createServer(5110);
    server.start();
    server.addConnectionListener(new TestNetworkStress());

    for (int i = 0; i < 1000; i++){
        Client client = Network.connectToServer("localhost", 5110);
        client.start();

        Thread.sleep(10);
        
        client.close();
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:TestNetworkStress.java


示例3: main

import com.jme3.network.Network; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException{
    Serializer.registerClass(PingMessage.class);
    Serializer.registerClass(PongMessage.class);

    Server server = Network.createServer(5110);
    server.start();

    Client client = Network.connectToServer("localhost", 5110);
    client.start();

    server.addMessageListener(new ServerPingResponder(), PingMessage.class);
    client.addMessageListener(new ClientPingResponder(), PongMessage.class);

    System.out.println("Client: Sending ping message..");
    client.send(new PingMessage());
    
    Object obj = new Object();
    synchronized (obj){
        obj.wait();
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:TestMessages.java


示例4: main

import com.jme3.network.Network; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {

        Serializer.registerClass(TestMessage.class);

        // Use this to test the client/server name version check
        //Server server = Network.createServer( "bad name", 42, 5110, 5110 );
        Server server = Network.createServer(5110, 5110);
        server.start();

        Client client = Network.connectToServer("localhost", 5110);
        client.start();

        client.addMessageListener(new TestThroughput(false), TestMessage.class);
        server.addMessageListener(new TestThroughput(true), TestMessage.class);

        Thread.sleep(1);

        TestMessage test = new TestMessage();
//        for( int i = 0; i < 10; i++ ) {
        while (true) {
//System.out.println( "sending." );
            client.send(test);
        }

        //Thread.sleep(5000);
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:27,代码来源:TestThroughput.java


示例5: createServer

import com.jme3.network.Network; //导入依赖的package包/类
public static void createServer(){
    serverApp = new SimpleApplication() {
        @Override
        public void simpleInitApp() {
        }
    };
    serverApp.start();

    try {
        Server server = Network.createServer(5110);
        server.start();

        ObjectStore store = new ObjectStore(server);
        store.exposeObject("access", new ServerAccessImpl());
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:TestRemoteCall.java


示例6: GameServer

import com.jme3.network.Network; //导入依赖的package包/类
/**
 * @param gameData 游戏数据
 * @param gameName 游戏名称
 * @param versionName 游戏的版本
 * @param versionCode 游戏版本代码
 * @param serverPort 端服端运行端口
 * @throws IOException 
 */
public GameServer(GameData gameData, String gameName, String versionName, int versionCode, int serverPort) throws IOException {
    // 不要设置为true,这会导致在Network.createServer创建Server后,第二次再创建时报异常:
    // java.lang.RuntimeException: Serializer registry locked trying to register class:class com.jme3.network.message.SerializerRegistrationsMessage
    // 这个问题在JME3.1发生,在3.0时没有问题。
    Serializer.setReadOnly(false);
    
    this.gameData = gameData;
    this.gameName = gameName;
    this.versionName = versionName;
    this.versionCode = versionCode;
    this.serverPort = serverPort;
    server = Network.createServer(gameName, versionCode , serverPort, serverPort);
    server.addConnectionListener(this);
    server.addMessageListener(this);
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:24,代码来源:GameServer.java


示例7: simpleInitApp

import com.jme3.network.Network; //导入依赖的package包/类
/**
 * Initialise the game.
 * @see SimpleApplication#simpleInitApp()
 */
@Override
public void simpleInitApp() {
  try {
    server = Network.createServer(port);
    server.start();
    new ServerNetListener(this, server, expectedClients);
  } catch (IOException e) {
    // TODO: Handle exception.
    System.err.println("Error creating server.");
  }

  this.flyCam.setEnabled(false);
  stateManager.attach(new PlayState(expectedClients));
}
 
开发者ID:meoblast001,项目名称:seally-racing,代码行数:19,代码来源:ServerApplication.java


示例8: TestChatClient

import com.jme3.network.Network; //导入依赖的package包/类
public TestChatClient(String host) throws IOException {
    super("jME3 Test Chat Client - to:" + host);

    // Build out the UI       
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setSize(800, 600);

    chatLog = new JEditorPane();
    chatLog.setEditable(false);
    chatLog.setContentType("text/html");
    chatLog.setText("<html><body>");

    getContentPane().add(new JScrollPane(chatLog), "Center");

    // A crude form       
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(new JLabel("Name:"));
    nameField = new JTextField(System.getProperty("user.name", "yourname"));
    Dimension d = nameField.getPreferredSize();
    nameField.setMaximumSize(new Dimension(120, d.height + 6));
    p.add(nameField);
    p.add(new JLabel("  Message:"));
    messageField = new JTextField();
    p.add(messageField);
    p.add(new JButton(new SendAction(true)));
    p.add(new JButton(new SendAction(false)));

    getContentPane().add(p, "South");

    client = Network.connectToServer(TestChatServer.NAME, TestChatServer.VERSION,
            host, TestChatServer.PORT, TestChatServer.UDP_PORT);
    client.addMessageListener(new ChatHandler(), ChatMessage.class);
    client.start();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:36,代码来源:TestChatClient.java


示例9: main

import com.jme3.network.Network; //导入依赖的package包/类
public static void main(String... args) throws Exception {
    initializeClasses();

    // Use this to test the client/server name version check
    Server server = Network.createServer(NAME, VERSION, PORT, UDP_PORT);
    server.start();

    ChatHandler handler = new ChatHandler();
    server.addMessageListener(handler, ChatMessage.class);

    // Keep running basically forever
    synchronized (NAME) {
        NAME.wait();
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:16,代码来源:TestChatServer.java


示例10: main

import com.jme3.network.Network; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException{
    Serializer.registerClass(Savable.class, new SavableSerializer());

    createServer();

    Client client = Network.connectToServer("localhost", 5110);
    client.start();

    ObjectStore store = new ObjectStore(client);
    ServerAccess access = store.getExposedObject("access", ServerAccess.class, true);
    boolean result = access.attachChild("Models/Oto/Oto.mesh.xml");
    System.out.println(result);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:14,代码来源:TestRemoteCall.java


示例11: main

import com.jme3.network.Network; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException{
    Serializer.registerClass(SomeObject.class);
    Serializer.registerClass(TestSerializationMessage.class);

    Server server = Network.createServer( 5110 );
    server.start();

    Client client = Network.connectToServer( "localhost", 5110 ); 
    client.start();

    server.addMessageListener(new TestSerialization(), TestSerializationMessage.class);
    client.send(new TestSerializationMessage(true));
    
    Thread.sleep(10000);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:16,代码来源:TestSerialization.java


示例12: start

import com.jme3.network.Network; //导入依赖的package包/类
public void start() throws IOException {
    if (client != null && client.isConnected()) {
        return;
    }
    client = Network.connectToServer(gameName, version, host, port);
    client.addClientStateListener(this);
    client.addMessageListener(this);
    client.start();
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:10,代码来源:GameClient.java


示例13: Main

import com.jme3.network.Network; //导入依赖的package包/类
public Main() {
    Properties properties = new Properties();
    try {
        properties.load(getClass().getClassLoader().
                getResourceAsStream("resources/net/client/network.properties"));
        magicallyousClient = Network.connectToServer(
                properties.getProperty("server.name", "Magicallyous Server"),
                Integer.parseInt(properties.getProperty("server.version", "1")),
                properties.getProperty("server.address", "localhost"),
                Integer.parseInt(properties.getProperty("server.port", "5465")), 
                Integer.parseInt(properties.getProperty("server.port", "5466")));
        // register serializable messages classes
        Serializer.registerClass(WelcomeMessage.class);
        Serializer.registerClass(AccountRegisterMessage.class);
        Serializer.registerClass(MagicallyousAccount.class);
        Serializer.registerClass(ServerServiceOutcomeMessage.class);
        Serializer.registerClass(LoginRequestMessage.class);
        Serializer.registerClass(LoginResponseMessage.class);
        Serializer.registerClass(PlayerNetInputMessage.class);
        // register listeners
        clientMessageListener = new ClientMessageListener();
        magicallyousClient.addMessageListener(clientMessageListener, 
                WelcomeMessage.class, PlayerNetInputMessage.class);
        magicallyousClient.start();
        System.out.println("Application connected to server " 
                + "name: " + properties.getProperty("server.name") 
                + " address: " + properties.getProperty("server.address") 
                + " port: " + properties.getProperty("server.port"));
    } catch (IOException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    }
    actualSceneName = magicallyousSceneName;
}
 
开发者ID:duodecimo,项目名称:magicallyous,代码行数:34,代码来源:Main.java


示例14: init

import com.jme3.network.Network; //导入依赖的package包/类
public static boolean init(String host, int port)
{
	Serializer.registerClass(UpdateMessage.class);
	Serializer.registerClass(AGVData.class);
       Serializer.registerClass(TruckCraneData.class);
       Serializer.registerClass(TruckSpawnData.class);
       Serializer.registerClass(StorageCranePickupData.class);
       Serializer.registerClass(SeaShipCraneData.class);
       Serializer.registerClass(BargeCraneData.class);
       
       Serializer.registerClass(SeaShipSpawnData.class);
       Serializer.registerClass(BargeSpawnData.class);
       Serializer.registerClass(ContainerData.class);
       Serializer.registerClass(StorageCraneDropoffData.class);
       
       Serializer.registerClass(InitMessage.class);
	try
	{
		client = Network.connectToServer(host, port);
	}
	catch (Exception e)
	{
		System.out.println(e);
		return false;
	}
	client.addMessageListener(new ClientListener());
	client.start();
	return true;
}
 
开发者ID:megagorilla,项目名称:Containing,代码行数:30,代码来源:ConnectionManager.java


示例15: initialize

import com.jme3.network.Network; //导入依赖的package包/类
/**
 * Create and start the server.
 * 
 * @param port
 * @return true if succesful, false otherwise
 */
public static boolean initialize(int port) {
	Serializer.registerClass(UpdateMessage.class);
	Serializer.registerClass(AGVData.class);
	Serializer.registerClass(TruckCraneData.class);
	Serializer.registerClass(TruckSpawnData.class);
	Serializer.registerClass(StorageCranePickupData.class);
	Serializer.registerClass(SeaShipCraneData.class);
	Serializer.registerClass(BargeCraneData.class);

	Serializer.registerClass(SeaShipSpawnData.class);
	Serializer.registerClass(BargeSpawnData.class);
	Serializer.registerClass(ContainerData.class);
	Serializer.registerClass(StorageCraneDropoffData.class);

	Serializer.registerClass(InitMessage.class);
	try {
		server = Network.createServer(port);
	}
	catch (Exception e) {
		System.err.println(e);
		return false;
	}
	server.addConnectionListener(new ConnectionListener());
	server.start();
	return true;
}
 
开发者ID:megagorilla,项目名称:Containing,代码行数:33,代码来源:ConnectionManager.java


示例16: startClient

import com.jme3.network.Network; //导入依赖的package包/类
public static void startClient() {
	Serializer.registerClass(Event.class);
	try {
		Thread.sleep(1000);
		client = Network.connectToServer("localhost", OpenRTSServer.PORT);
		client.addClientStateListener(new ClientStateListener());
		client.addMessageListener(new MessageListener(), Event.class);
	} catch (IOException | InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	client.start();
	
	EventManager.register(instance);
}
 
开发者ID:methusalah,项目名称:OpenRTS,代码行数:16,代码来源:ClientManager.java


示例17: simpleInitApp

import com.jme3.network.Network; //导入依赖的package包/类
@Override
public void simpleInitApp() {
	try {
		myServer = Network.createServer(PORT, PORT);
		myServer.addMessageListener(new MessageListener(), Event.class);
		myServer.addConnectionListener(new ConnectionListener());
		myServer.start();
		logger.info("Server listening at :" + PORT);

	} catch (IOException e) {
		e.printStackTrace();
	}
	Serializer.registerClass(Event.class);
}
 
开发者ID:methusalah,项目名称:OpenRTS,代码行数:15,代码来源:OpenRTSServer.java


示例18: ClientMain

import com.jme3.network.Network; //导入依赖的package包/类
/**
 * Construct a client main application with the given arguments.
 *
 * @param address
 *            address to use
 * @param port
 *            port
 * @throws IOException
 */
public ClientMain(String address, int port, String name) throws IOException {
	Packets.register();
	client = Network.connectToServer(address, port);
	this.name = name;
	setDisplayFps(false);
       setDisplayStatView(false);
}
 
开发者ID:GSam,项目名称:Game-Project,代码行数:17,代码来源:ClientMain.java


示例19: ServerMain

import com.jme3.network.Network; //导入依赖的package包/类
/**
 * Construct a server main application.
 *
 * @param port
 *            port to use
 * @throws IOException
 */
public ServerMain(int port) throws IOException{
	Packets.register();
	server = Network.createServer(port);
}
 
开发者ID:GSam,项目名称:Game-Project,代码行数:12,代码来源:ServerMain.java



注:本文中的com.jme3.network.Network类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EditDistance类代码示例发布时间:2022-05-23
下一篇:
Java ViewStructure类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap