...
There are few ways to open ports in the FIX Antenna-based server application:
Listening ports can be defined via FIXServer constructors:
Code Block language java // Create a FIX server, with default configuration from fixengine.properties, which listens listento ports 8090, 8091, 8092 FIXServer server = new FIXServer(8090, 8091, 8092); server.start(); ...
Code Block language java // Create a FIX server, with custom configuration, which listens listento ports 8090, 8091, 8092 FIXServer server = new FIXServer(serverConfiguration, 8090, 8091, 8092); server.start(); ...
- It's possible to set listening ports for an already existing FIXServer instance but before its start:
Code Block language java // Create a FIX server, with custom configuration, butor withoutthat anydoesn't whichlisten listento ports FIXServer server = new FIXServer(); // Configure server to listen to ports 8090, 8091, 8092 server.setPorts(8090, 8091, 8092); server.start(); ...
There is also a way to open a listening port for an already started server:
Code Block language java // Create a FIX server, with custom configuration, butor withoutthat anydoesn't whichlisten listento ports FIXServer server = new FIXServer(); server.start() ... // Open port 8090 to listen server.openPort(8090);
The FIXServer.openPort() method can be used with the second parameter, which defines is if the port can be automatically closed when deregistered the last acceptor for such port (see Managing listening ports via configuration):
Code Block language java // Create a FIX server, with custom configuration, butor withoutthat anydoesn't whichlisten listento ports FIXServer server = new FIXServer(); server.start() ... // Open port 8090 to listen server.openPort(8090, true); // autoclose = true
FIXServer.openPort() method can be used with the second parameter, which defines is the port can be automatically closed when deregistered the last acceptor for such port:
...
FIXServe.getPorts() return a list of actually configured ports. It also returns a list of ports, defined with constructor or with setPorts() method, before the start:
Code Block language java FIXServer server = new FIXServer(); server.getPorts(); // returns {} server.setPorts(8090, 8091, 8092); server.getPorts(); // returns {8090, 8091, 8092} server.start; server.getPorts(); // returns {8090, 8091, 8092}
FIXServe.getOpenPorts() return a list of opened ports - only those ones with can accept incoming connections:
Code Block language java FIXServer server = new FIXServer(); server.setPorts(8090, 8091, 8092); server.getOpenPorts(); // returns {} server.start; server.getOpenPorts(); // returns {8090, 8091, 8092}
Close open ports
Closing Closure of the port explicitly is performed in the following way:
Code Block | ||
---|---|---|
| ||
FIXServer server = new FIXServer(); ... server.getOpenPorts(); // returns {8094} server.closePort(8094); server.getOpenPorts(); // returns {}: 8094 was auto closed |
...
FIX Antenna Java engine can automatically manage listening ports for server during registration/deregistration acceptor sessions. It works only if the port property is defined for the acceptor session. Additionally, such an acceptor could be connected only on the defined port:
Code Block | ||
---|---|---|
| ||
// Define configuration for acceptor with a port parameter SessionParameters acceptorParameters = new SessionParameters(); acceptorParameters.setSenderCompId("acceptor"); acceptorParameters.setTargetCompId("target1"); acceptorParameters.setPort("8090"); // check that server is started but there is no open ports server.getOpenPorts(); // returns {} // register acceptor server.registerAcceptorSession(sessionParameters); server.getOpenPorts(); // returns {8090} |
...