📄 client.java
字号:
import hla.rti.*;import se.pitch.prti.*;import java.net.URL;import java.io.*;class Client extends FederateAmbassador_Impl{ RTIambassador _rtiAmbassador; int _messageId; int _parameterIdText; boolean canGo = true; public static void main(String[] args) { new Client().run(args); } public void run(String[] args) { try { String rtiHost = (args.length > 0) ? args[0] : "localhost"; _rtiAmbassador = RTI.getRTIambassador(rtiHost, 8989); try { _rtiAmbassador.createFederationExecution( "ChatRoom", new URL("file:chat.fed")); } catch (FederationExecutionAlreadyExists ignored) { } _rtiAmbassador.joinFederationExecution("Client", "ChatRoom", this); _messageId = _rtiAmbassador.getInteractionClassHandle( "Communication"); _parameterIdText = _rtiAmbassador.getParameterHandle( "Message", _messageId); _rtiAmbassador.subscribeInteractionClass(_messageId); _rtiAmbassador.publishInteractionClass(_messageId); int count = 0; String numList = new String(); int num; { // Create 10 random numbers from 0 to 100 and concatenate them into a string, separated by spaces // Then print out Unsorted List. Use numList variable for an unsorted string. // Add your code here -------------------------------------------------------- // --------------------------------------------------------------------------- SuppliedParameters parameters = RTI.suppliedParametersFactory().create(1); byte[] value = numList.getBytes(); parameters.add(_parameterIdText, value); canGo = false; _rtiAmbassador.sendInteraction(_messageId, parameters, null); // Delay until Server is done with request, then quit while (canGo == false) { } } _rtiAmbassador.resignFederationExecution( ResignAction.DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES); try { _rtiAmbassador.destroyFederationExecution("ChatRoom"); } catch (FederatesCurrentlyJoined ignored) { } } catch (Exception e) { e.printStackTrace(); } } public void receiveInteraction ( int interactionClass, ReceivedInteraction theInteraction, byte[] userSuppliedTag) throws InteractionClassNotKnown, InteractionParameterNotKnown, FederateInternalError { try { if (interactionClass == _messageId) { String message = ""; for (int i = 0; i < theInteraction.size(); ++i) { if (theInteraction.getParameterHandle(i) == _parameterIdText) { message = new String(theInteraction.getValueReference(i)); // Display sorted list here ------------------------------------------ // ------------------------------------------------------------------- } } canGo = true; } } catch (ArrayIndexOutOfBounds e) { System.out.println(e.getMessage()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -