The online racing simulator
Ports used by InSim, OutSim and OutGauge
In the program I'm writing I'm not receiving OutSim or OutGuage packets, although I am receiving InSim packets correctly. To make matters more confusing, at one point I was using a different method of connecting UDP sockets and was receiving OutSim and OutGauge packets. I think the problem may lie in a technicality with the new method.

Here is a blind question, that perhaps only Scawen can answer: Does LFS send all InSim, OutSim and OutGauge packets from the same port on the server?

A little more info for the curious: I'm writing the code in Java. Initially I was using the DatagramSocket and DatagramPacket classes from the java.net package. I switched to using a DatagramChannel from the java.nio.channels package because of the cleaner architecure and the speed. To use the DatagramChannel, it has to be bound to an address on the server side, where "address" means "IP address and port number". It will only accept datagrams from the address it's bound to. So, my belief is that if a datagram comes from a different port on the same machine it won't be accepted. If that's the case, and LFS is sending using different ports, I need to rethink things. I would use something like Ethereal to sniff packets, but it doesn't see packets on the loopback address because Windows shortcuts that special case and doesn't go through the network stack Anyway, thanks for any help!

--
Rob
#2 - Stuff
Hmm.. I'm pretty sure you can specifiy whatever ports you want. For InSim, you tell it the port you're going to send stuff to with the /insim switch and the port for it to send stuff back to in the ISI packet. OutSim and OutGauge ports can be controlled through the cfg.txt or with OutGauge, through that new InSim packet I think.

imo, its safer to keep them on separate ports of course but I don't think the same ports would hurt much either if handled correctly.

For the type of Java connection, I've had no problems with the DatagramSocket/Packet stuff, as you can see in my little example in this thread.
OK, I've answered my own question; yes InSim, OutSim and OutGuage all send from different ports. So, I got it working for all the above

The results are encouraging too. With OutSim or OutGuage packets coming every 100ms, and a text representation of them being printed to stdout, I'm seeing a small ding in my fps. If I redirect stdout to /dev/null, I'm hardly seeing a dip at all.

I now have the beginnings of a simple to use library that allows you to register for notification of any Insim, OutSim or OutGuage packet. It also allows you send any of the InSim request packets to the server. I've only written tests for part of the library, so haven't verified all of my packet parsing, but so far it looks pretty good. Here's an example of a simple program that requests the version from the server and prints out the response when it gets it:


import org.kerf.insim.Client;

public class Main implements InSimListener {
private Client client;

public void run() {

try {
String toAddress = "localhost"; // Address of server
int toPort = 33333; // Port on which server is listening for InSim requests.
String adminPassword = "password"; // Administration password for server (if applicable)

client = new Client(toAddress, toPort, adminPassword);

client.addListener("VER", this); // Listen for Version packets
client.connect();

VersionRequest versionRequest = new VersionRequest();
client.send(versionRequest);

} catch (Exception e) {
e.printStackTrace();
client.close();
}
}

// InSimListener implementation
public void packetReceived(InSimResponse response) {
if(response instanceof VersionResponse) {
VersionResponse versResponse = (VersionResponse)response;

System.out.println("Product: " + versResponse.getProduct());
System.out.println("Version: " + versResponse.getVersion());
System.out.println("Network version: " + versResponse.getNetVersion());
}
}

static public void main(String[] args) {
Main testConnect = new Main();
testConnect.run();
}

}

The code is similar for any InSim packet, just register for notification then send the request and handle it in the InSimListener implementation. All of the Initialization, ACKs and networking is taken care of for you. Let me know if you're interested in trying it out.

--
Rob

FGED GREDG RDFGDR GSFDG