PDA

View Full Version : Java - JInSim - a Java InSim library


rheiser
17th August 2006, 17:04
JInSim is an easy to use Java library for communicating with InSim, OutSim and OutGauge. It's currently in pre-alpha form, but I've created a few small examples that work correctly to get you started. The examples are well commented and straightforward, so if you have any Java knowledge at all, you should be able to understand them and move on to creating your own clients.

Right now, the core communication with InSim is done and I'm starting to create specialized classes for common use scenarios. The first one is a "RaceEventClient" that will notify you about crashes in progress and the closest race on the track. What I really would like is some feedback from people who are interested in using a library like this.

I've created a SourceForge project where you can get the code through anonymous CVS. If you aren't familiar with CVS and want JInSim, let me know. You can find the project at http://jinsim.sourceforge.net

Thanks,

--
Rob

the_angry_angel
17th August 2006, 17:28
Nice work Rob :up: I probably won't use it, but the more libraries the better :D I've added it as a link to the FAQ thread.

Dygear
18th August 2006, 06:26
I don't quite know how to word this. I've used CodeWarrior at school, but I don't really know where to start with Java. I'd love to use it for a web program I'm working on. Any clues as where I should look?

rheiser
18th August 2006, 06:41
1. Make sure you have java installed. You can download a JDK from http://java.sun.com if you don't. If you can type "java -version" at a command line and get version information, you're on your way.

2. Download JInSim from SourceForge. Go to http://sourceforge.net/projects/jinsim/ and click the big green Download button to download the zip file. The current one is jinsim-0.1.zip

3. Unzip jinsim-0.1.zip somewhere on your hard drive that's handy.

4. Look at the README file inside the newly unzipped directory. There's some information there on how to run the "Hello World!" example. Once you have that working, you're well on your way.

To start off with, you may just want to edit simple java files with your favorite text editor, figure out how to compile them with javac and run them. Once you're comfortable with that, you can download one of the freely available Java IDEs like Eclipse or NetBeans. I use Eclipse, because that's what I use at work. I actually prefer IntelliJ, but that's a (spendy) commercial package. If you have any questions, let me know.

--
Rob

Dygear
19th August 2006, 06:15
I start IntelliJ and it thows me out to a screen full of XML when I try to make a web application. I don't want a screen with XML, I want a screen where I can write java code. Now I've never done a java program for the web, but I don't think this was ment to happen. I need ... a tutorial. Anyone got a good one for making java programs for web browser?

rheiser
26th August 2006, 17:22
I'll announce new releases on this thread from now on instead of spamming the forum with new threads. The new release includes:

- An experimental client using the selectable sockets from Java's nio package.
- Fixes for thread synchronization (thanks Brilwing!)
- Fixes and additions to the request and response classes.
- Additions to InSimHelper
- Fixes to the packaging so that the speedometer example can find its images :)
- Fixes to some of the math on the RaceEventClient
- More documentation.

abz1
26th August 2006, 23:22
Im sure theres nothing wrong with Brilwing way, but (http://www.lfsforum.net/member.php?u=19797) you might want to check this out.

http://java.sun.com/javase/6/docs/api/java/util/concurrent/locks/Lock.html

rheiser
27th August 2006, 05:27
Yep, the new features of Java 6 (Java SE 6? Java 1.6? What's with Sun and their versions?) Anyway...the new features are nice. I'm trying to stay 1.4 compliant for right now. You'll notice I don't use things like parameterized types in JInSim. I'm not doing anything fancy with locks either, so the cool new Lock objects wouldn't make a difference, I don't think. Thanks for pointing them out, though. It made me sit down and check out the feature more deeply.

Tanuva
28th August 2006, 14:39
Oh nice to see someone developing such thing, will be very useful... :> :thumb:

Pablo.CZ
2nd January 2007, 18:33
I'm trying to make my own appl based on JInSim v0.3 and I have problems with getting

total time, split1 time, split2 time, split3 time, (last) lap time
front gap, back (rear) gap
actual lap number, total number of laps

Thx for help.

z3r0c00l
2nd January 2007, 23:24
Brilliant!!!!!!!

I write AI programs in Java, and this will save me a lot of work!

thank you so much!

Brilwing
3rd January 2007, 10:34
I'm trying to make my own appl based on JInSim v0.3 and I have problems with getting

total time, split1 time, split2 time, split3 time, (last) lap time
front gap, back (rear) gap
actual lap number, total number of laps

Thx for help.

I have done such a program (except the front and back gap) and you find the source code here: https://openbakery.org/svn/repos/trunk/gstats/

The output of the program is a textfile that contains the stats and you find an example here:
http://dev.guglhupf.net/gstats/downloads/SO5_race_0608271626.gstats

I use the *.gstats files in a php program to manage the austrian championship league. (see liveforspeed.at -> Events/ÖLFSM)

Pablo.CZ
4th January 2007, 10:48
Thank you Brilwing. I don't have some packages you are using (org.apache.commons.logging*) but I'm working on it. I'm new to Java, so my progress is slow.

Brilwing
4th January 2007, 11:56
You can put the jars manually in your classpath. You need:
commons-logging: http://jakarta.apache.org/commons/logging/
commons-cli: http://jakarta.apache.org/commons/cli/
log4j: http://logging.apache.org/log4j/docs/
junit: http://junit.org
and jinsim ;)

Or you can use Yeast, which is a tool that a made to manage these dependences. This means that the jars automatically downloaded ;)
Yeast can be found here: http://yeast.openbakery.org

Brilwing
17th May 2007, 09:26
I currently working on updating jinsim for patch X. It is not finished by now, but you can find a first test release here: http://liveforspeed.at/download/jinsim-0.4.91.zip
In this release all jinsim response and request packets are updated and should now work with lfs patch w24, but only UDP connections are supported right now. I will add the TCP support soon.
JInSim now requieres Java 5.0.

You should also look into the Changes file and also exam the examples, because I also have done some refactorings.

phelan
17th May 2007, 10:16
Great :) Now if there only was support for tyre temp and damage output in the game, ... but anyways, i'll definately have some use for the jinsim lib.

Brilwing
19th July 2007, 16:28
Here is a new package of the current jinsim for patch x: http://liveforspeed.at/download/jinsim-0.4.95.zip

Changes:
- Both TCP and UDP is supported
- New button system added
- Encoding support. The LFS codepages are converted.

So this package should now have all features of the new InSim in patch x. If I missed something let me know :D

joelbarton1987
29th July 2007, 19:59
Here is a new package of the current jinsim for patch x: http://liveforspeed.at/download/jinsim-0.4.95.zip

Changes:
- Both TCP and UDP is supported
- New button system added
- Encoding support. The LFS codepages are converted.

So this package should now have all features of the new InSim in patch x. If I missed something let me know :D

i keep getting this error Microsoft Windows XP [Version 5.1.2600]

Exception in thread "main" java.lang.NoClassDefFoundError: org/kerf/jinsim/examp
les/helloworld/Main
:scratchch:shrug::scratchch:shrug::scratchch:shrug ::scratchch:shrug::scratchch:shrug:

please help ............... me

Brilwing
30th July 2007, 08:44
i keep getting this error Microsoft Windows XP [Version 5.1.2600]

Exception in thread "main" java.lang.NoClassDefFoundError: org/kerf/jinsim/examp
les/helloworld/Main
:scratchch:shrug::scratchch:shrug::scratchch:shrug ::scratchch:shrug::scratchch:shrug:

please help ............... me
I'm wondering how you get this error.
Try this:
java -cp dist\jinsim.jar;lib\commons-logging-1.0.4.jar org.kerf.jinsim.examples.helloworld.Main
You need Java 5.0 of course.

joelbarton1987
30th July 2007, 09:53
I'm wondering how you get this error.
Try this:
java -cp dist\jinsim.jar;lib\commons-logging-1.0.4.jar org.kerf.jinsim.examples.helloworld.Main
You need Java 5.0 of course.


same error aaaarrrrrrrggggg ....... any segestions

Brilwing
30th July 2007, 16:21
same error aaaarrrrrrrggggg ....... any segestions

You must execute this command in the jinsim-0.4.95 directory.


C:\workspace\jinsim-0.4.95>java -cp dist\jinsim.jar;lib\commons-logging-1.0.4.jar org.kerf.jinsim.examples.helloworld.Main 192.168.99.
2 60000

vs.

C:\workspace\jinsim-0.4.95>cd ..

C:\workspace>java -cp dist\jinsim.jar;lib\commons-logging-1.0.4.jar org.kerf.jinsim.examples.helloworld.Main 192.168.99.2 60000
Exception in thread "main" java.lang.NoClassDefFoundError: org/kerf/jinsim/examples/helloworld/Main

GeForz
30th July 2007, 16:39
Perhaps you don't have the system classpath var set. try adding the current directory (".") to the -cp list

java -cp .;dist\jinsim.jar;lib\commons-logging-1.0.4.jar org.kerf.jinsim.examples.helloworld.Main 192.168.99.
2 60000

Brilwing
30th July 2007, 19:50
The system classpath is not need cause the Main class is in the jinsim.jar

shiny_red_cobra
30th July 2007, 19:59
i keep getting this error Microsoft Windows XP [Version 5.1.2600]

Exception in thread "main" java.lang.NoClassDefFoundError: org/kerf/jinsim/examp
les/helloworld/Main

Simple workaround: use Eclipse (http://www.eclipse.org/downloads/).

joelbarton1987
7th August 2007, 08:27
Simple workaround: use Eclipse (http://www.eclipse.org/downloads/).

witch one do i download ??????

joelbarton1987
7th August 2007, 08:40
You must execute this command in the jinsim-0.4.95 directory.


C:\workspace\jinsim-0.4.95>java -cp dist\jinsim.jar;lib\commons-logging-1.0.4.jar org.kerf.jinsim.examples.helloworld.Main 192.168.99.
2 60000

vs.

C:\workspace\jinsim-0.4.95>cd ..

C:\workspace>java -cp dist\jinsim.jar;lib\commons-logging-1.0.4.jar org.kerf.jinsim.examples.helloworld.Main 192.168.99.2 60000
Exception in thread "main" java.lang.NoClassDefFoundError: org/kerf/jinsim/examples/helloworld/Main


ok thanks but new error : error = in dedi host screen when trying to load insim : = " insim: first byte in packet does not match size "

:(:shrug::(:shrug::(:shrug::(:shrug::(:shrug:

PLEASE HELP!!!!!

Brilwing
7th August 2007, 12:08
ok thanks but new error : error = in dedi host screen when trying to load insim : = " insim: first byte in packet does not match size "
Hmm, I have tested this example only with LFS not with the dedi, so I don't know if the example works with a dedi, because it only sends a chat message. But you error message look like that you are using an older dedi version. Are you using the latest dedi version patch X?

@Eclipse: download this: http://www.eclipse.org/downloads/moreinfo/java.php

shiny_red_cobra
9th August 2007, 22:11
Ok I've managed to run the Hello World thingy, and it does what it's supposed to do in LFS, but in the console I get this over and over (nonstop):

java.nio.channels.ClosedChannelException
at sun.nio.ch.DatagramChannelImpl.ensureOpen(Datagram ChannelImpl.java:107)
at sun.nio.ch.DatagramChannelImpl.read(DatagramChanne lImpl.java:313)
at org.kerf.jinsim.UDPChannel.receive(UDPChannel.java :120)
at org.kerf.jinsim.AbstractChannel.run(AbstractChanne l.java:57)
at java.lang.Thread.run(Thread.java:619)

Brilwing
10th August 2007, 06:57
Hmm I don't have this exception when I run the hello world example. Nevertheless, I have updated jinsim that this exception is handled, cause it indicates that the jinsim connection is closed.

here you find the update: http://liveforspeed.at/download/jinsim-0.4.96.zip

joelbarton1987
11th August 2007, 07:29
Hmm, I have tested this example only with LFS not with the dedi, so I don't know if the example works with a dedi, because it only sends a chat message. But you error message look like that you are using an older dedi version. Are you using the latest dedi version patch X?

@Eclipse: download this: http://www.eclipse.org/downloads/moreinfo/java.php

yep using the latest release 0.5 X10 ...... :smileypul:scratchch

Brilwing
5th December 2007, 20:54
I have created new package of jinsim with the latest fixes:
http://liveforspeed.at/download/jinsim-0.4.97.zip (http://liveforspeed.at/download/jinsim-0.4.96.zip)

* Some fixes at the button requests
* added java.lang.String to LFS codepages encoding
* fixed a synchronizing issue when sending lots of insim requests
* and maybe some more that I can't remember ;)

Brilwing
12th December 2007, 08:14
I updated jinsim with the minor X30 changes:
http://liveforspeed.at/download/jinsim-0.4.99.zip

Also changed:
* InSim relay support is now included + example program
* Fixes at the comp car and MCI requests
* Fixes a the set camera request
* Added a Track enum so that track codes like 100 or BL1 can be converted in an enum value and then to the real trackname.

I have tested this version only with a X30 Dedi, but it should also work with X10.

GeForz
12th December 2007, 17:50
Are the examples shipped within the zip file for older versions or are they just not working? ^^

The raceclient example throws a nullpointer exception

Brilwing
12th December 2007, 20:41
Yes some examples do not work, cause I haven't updated all by now. If everything is stable the version number whould be 0.5 :D

The UDPChannel has some bugs, and I will fix this soon, until then try the examples using the TCPChannel.

GeForz
12th December 2007, 23:09
oh btw your NodeLap type is missing the position byte (and remember to change it in the CompCar, too when you change the NodeLap :))

and in the Client class the bit flag with value 16 is not for new players but for node lap packets ;)

Brilwing
13th December 2007, 08:34
Thx, fixed this in my version.
I will post a new version as soon as I have fixed the UDP issue.

wheel4hummer
16th December 2007, 13:34
It won't compile for me. I'm really not sure what the problem is:

insimApplication.java:6: unreported exception java.io.IOException; must be caught or declared to be thrown
Client insimConnection1 = new Client("localhost", 6699, "adminpass");

GeForz
16th December 2007, 18:33
You just have to catch the exception? ^^
That Client class isn't the one in the library, right?

Brilwing
16th December 2007, 22:14
Yes, the connect throws an IOException.

Starblue
23rd December 2007, 17:22
I updated jinsim with the minor X30 changes:
http://liveforspeed.at/download/jinsim-0.4.99.zip

Also changed:
* InSim relay support is now included + example program
* Fixes at the comp car and MCI requests
* Fixes a the set camera request
* Added a Track enum so that track codes like 100 or BL1 can be converted in an enum value and then to the real trackname.

I have tested this version only with a X30 Dedi, but it should also work with X10.
Thnx for the update Brilwing! :)
There's a little mistake in SetCarCameraRequest, line 55:
super(PacketType.CAMERA_POSITION, 8);it should be:
super(PacketType.SET_CAR_CAMERA, 8);Thanks again for all your work :)

Starblue

Brilwing
4th January 2008, 14:44
new version: http://liveforspeed.at/download/jinsim-0.5rc1.zip

Changes:
* Renamed packages from org.kerf to net.sf
* Fixed camera packet (thx. Starblue)
* UDP communication works now again
* OutGauge and OutSim also works again
* Fixed the not working examples, and all should work now fine.

All I wanted in version 0.5 is now included so this is the first release candidate. ;)

Starblue
7th January 2008, 17:23
new version: http://liveforspeed.at/download/jinsim-0.5rc1.zip

Changes:
* Renamed packages from org.kerf to net.sf
* Fixed camera packet (thx. Starblue)
* UDP communication works now again
* OutGauge and OutSim also works again
* Fixed the not working examples, and all should work now fine.

All I wanted in version 0.5 is now included so this is the first release candidate. ;)
Hi Brilwing,
I get a "page not found" on that link :)
Two more things I fixed on my local version of 0.4.99:
SetCarCameraRequest: uniqueId and cameraType were inverted, the correct order is:
data.put(uniqueId);
data.put(cameraType);
NodeLap: the Position byte (after PlayerId byte) was not implemented. I added the getter/setter for position and setPosition(buffer.get()); after setPlayerId(buffer.get()); in the constuctor.

Starblue

Brilwing
7th January 2008, 19:00
Hi Brilwing,
I get a "page not found" on that link :)
Two more things I fixed on my local version of 0.4.99:
SetCarCameraRequest: uniqueId and cameraType were inverted, the correct order is:
data.put(uniqueId);
data.put(cameraType);
NodeLap: the Position byte (after PlayerId byte) was not implemented. I added the getter/setter for position and setPosition(buffer.get()); after setPlayerId(buffer.get()); in the constuctor.

Starblue

Ups, was a typo in the Url...

So here we go: http://liveforspeed.at/download/jinsim-0.5.rc2.zip

Changes:
* fixed SetCarCameraRequest (thx Starblue)
* added Car enum

(set position is already in 0.5rc1 at the NodeLap)

Starblue
10th January 2008, 16:52
So here we go: http://liveforspeed.at/download/jinsim-0.5.rc2.zip

Thanks for the update :)
I'm currently using 0.5.rc2 for a project and I noticed the following behaviour, while connecting with the SimpleClient class:
if an unchecked exception is thrown in the registered listener, the jvm will start increasing its memory without limits, until.... I had to terminate it because my pc was freezing :)
That happened me twice, once for a mistaken object cast and once because I received a string of unexpected size and went out of bound doing a substring :)
If I had enabled logging, I guess I would have seen the "Something went wrong!" message of AbstractChannel.java line 122, as I think the exception got caught there.
As it's not nice to have an application crash everything by stealing all the available memory, you may want to change that behaviour..
Maybe you could have a dedicated try/catch around the notify action, like this:
try {
client.notifyListeners(packetData);
}
catch (Exception e) {
log.error("Something went wrong!", e);
}This way the custom listeners can be wrong and throw whatever they like but it won't crash the whole InSim connection & program.
It's probably not the best way to handle the situation, but I think it may be worth to change it.

Starblue

Brilwing
13th January 2008, 19:14
try {
client.notifyListeners(packetData);
}
catch (Exception e) {
log.error("Something went wrong!", e);
}This way the custom listeners can be wrong and throw whatever they like but it won't crash the whole InSim connection & program.
It's probably not the best way to handle the situation, but I think it may be worth to change it.

Starblue
Sorry I haven't got the time to test this problem, but I read the code and I have an idea to solve this problem without using an extra try-catch. I hope I find time this week to fix this.

Starblue
4th February 2008, 12:14
Hi Brilwing,
I've found a problem with the MessageResponse class.
I wanted to check what users said so I used getTextStart() to make a substring of the getMessage() and filter their name to get only the actual text they typed.
However, it didn't work for people with "^" in their name.. that's because LFS encodes it with "^^" and getMessage() returns it to just "^"..
So basically the number of characters in getMessage() is not the original one and so the position returned by getTextStart() becomes wrong.
I changed my local copy of MessageResponse constructor like this:

public void construct(ByteBuffer buffer) throws BufferUnderflowException {
super.construct(buffer);
buffer.position(buffer.position()+1);
connectionId = buffer.get();
playerId = buffer.get();
typedByUser = buffer.get();
textStart = buffer.get();
message = getString(buffer, 128);

// Starblue 04/01/2008
// Rewind the buffer and check how long the "pre-message" part really is:
int pos = buffer.position();
buffer.position(pos-128);

String preMessage = getString(buffer,textStart);
textStart = (byte)(preMessage.length()+1);

buffer.position(pos);
}
After this change, it became safe to get the typed message like this:
String typedMessage = response.getMessage().substring(response.getTextSt art());Starblue

Starblue
12th February 2008, 15:10
Hi Brilwing,
I found another problem related to the try/catch in AbstractChannel: sometimes I get this exception:
15:13:58,890 ERROR - Something went wrong!
java.io.IOException: Connessione interrotta dal software del computer host
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(Unknown Source)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.read(Unknown Source)
at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
at net.sf.jinsim.TCPChannel.receive(TCPChannel.java:3 6)
at net.sf.jinsim.AbstractChannel.run(AbstractChannel. java:60)The description "Connessione interrotta dal software del computer host" (which means "connection interrupted by computer host software") makes me think that this a particular implementation of an event similar to the ClosedChannelException, for which you had already provided a try/catch:
try {
numberRead = receive(sizeBuffer);
} catch (ClosedChannelException ex) {
// do nothing chase numberRead is already -1
}
Unfortunately, this time it's an IOException so it does not get caught into the ClosedChannelException catch and it goes on to be catched by the generic try/catch you've put at the end of the loop:
while (running) {
try {
[...]
} catch (Exception e) {
log.error("Something went wrong!", e);
}
}As there is no action in the catch to solve the problem, the thread keeps looping and logging the same error, eventually filling up all the space available on the disk and crashing the program...
(I think this explains my previous problem where I had not enabled logging on disk, so it filled up memory instead of disk space).
I'm going to put a return statement in the generic Exception catch, so that if something "unexpected" happens, the thread stops working (since it is not supposed to be able to "fix" an unexpected event anyway).

Starblue

Brilwing
14th February 2008, 18:24
Here is a new jinsim release 0.5.rc4: http://downloads.sourceforge.net/jinsim/jinsim-0.5.rc4.zip?use_mirror=osdn

Changes:

Fixed the bugs Starblue reported:

fixed the endless loop when the ResponseListener throws an exception
The MessageResponse getMessage only returns the message without the driver name. For the driver name use the getDriverName() method
Changed the ChannelCloseException to an IOException so that the Channel is closed when an error happened.

minor fixes at the buttons

Starblue
15th February 2008, 13:13
Thank you Brilwing :)

Starblue

Starblue
24th February 2008, 22:42
Hi Brilwing,
I wanted to use the prefix variable in the ISP_ISI packet, but the Client class generates its InitRequest inside the connect method and it's not possible to set a prefix from outside. Could you add a prefix parameter in the next release? :)

Starblue

Brilwing
25th February 2008, 09:04
Ok I will add this in the next release ;)

Starblue
1st April 2008, 17:14
Ok I will add this in the next release ;)
Hi Brilwing,
any plans about the next release date? :)

Starblue

Brilwing
3rd April 2008, 07:31
Hi Brilwing,
any plans about the next release date? :)

Starblue

I was busy with other stuff, I try to create a version in the next days.

Starblue
4th April 2008, 20:14
I was busy with other stuff, I try to create a version in the next days.
Excellent :)
I'm currently working on a new version of the tracker for IGTC endurance league and it could benefit from the "hide message with special prefix" feature :)

Starblue

mcgas001
4th April 2008, 20:17
Starblue: There is a way around it. You could send a clickable button to all the players on track. Maybe "Panic" or "Help" button. When clicked, It sends a message to all admins privatly(MTC).

Starblue
4th April 2008, 23:26
Starblue: There is a way around it. You could send a clickable button to all the players on track. Maybe "Panic" or "Help" button. When clicked, It sends a message to all admins privatly(MTC).
Yes, thanks for the suggestion :) We already thought about using a button but clicking a button with a mouse while you are driving is a lot less easy than just pushing a binded button on your wheel :)
Plus, there is another workaround: modifying the library by myself :) But I prefer to use official library releases if possible :)

Starblue

Brilwing
7th April 2008, 13:42
Here a new version 0.5rc5:

https://sourceforge.net/project/showfiles.php?group_id=174994

Changes:
* added prefix for the init request
* fixed NodeLapInfoResponse

Starblue
13th April 2008, 23:27
Here a new version 0.5rc5:

https://sourceforge.net/project/showfiles.php?group_id=174994

Changes:
* added prefix for the init request
* fixed NodeLapInfoResponse
Thanks :)

Starblue

Technique
22nd April 2008, 01:48
Nice work guys. Has anyone used jinsim with outgauge?

I played around with a bit today. I was wondering what kind of performance you guys were seeing.

Running the Speedometer example with a replay I'm frequently seeing a delay of ~1 second or more. It's especially noticeable in higher power cars like the GTR's that can stop on the dime.

The specs of my system are:
AMD Athlon 3400+
6800GT
1GB memory
Java 6u3
FPS: ~90

I tried running a different setup:
* LFS on the AMD machine above
* Speedo example on a lan machine
- 1.86ghz Pentium M laptop
- 2GB memory
- onboard video (gets 6-10fps running LFS)
- Java 6u3

I got roughly the same performance. For my final test, I created my own test class using active rendering and it seemed to improve a bit but there was still a noticeable delay. So I guess I was wondering... is anyone is using JInsim for realtime stuff with outgauge and having good results? Perhaps I just need to upgrade my h/w :)

Also, besides the performance issues, I noticed the outgauge response would often contain bad speed values. For example, the speed should be 60mph but getSpeed() returns 7.56005E-39. This happens once every few seconds causing the speedometer needle to flicker to ~0mph. To prevent this I just ignore any speed updates greater than 0 and less than 1. The needle rotation also jumps past the 270 degrees even though it shouldn't be anywhere near that value. I'm not sure if this is a bug in JInsim or LFS's outgauge.

I should point out that I've done all my tests with multiplayer replays. I'm not sure if that causes any issues.

Brilwing
22nd April 2008, 06:32
I only used OutGauge in the Speedometer example and with the short tests I can remember any delays, but my tests were only very brief.

I will try to run some longer tests and do also so some profiling.

Technique
24th April 2008, 04:50
I'm getting great performance out of it now. I think I might have just had too many applications open at the time :shrug:

Brilwing
24th April 2008, 08:11
I'm getting great performance out of it now. I think I might have just had too many applications open at the time :shrug:

Nevertheless i will run a test in the profile, just to make sure that everything is fine ;)

MaKaKaZo
7th July 2008, 08:00
I can't get the Hello World example to compile either in command line or using Eclipse. I don't care much about command line as I wouldn't be using it, but... damn Eclipse is such a bitch! I don't know how to create a project from an existing java file. The other day I think I got it, but there were errors everywhere and I think it was because I had to link the commons logging jar file to my project, and I couldn't do it. And Eclipse tutorials are quite poor...

Could anyone post a quick guide on running the Hello World example in Eclipse? It could be very useful for beginners in Java like me to get started :)

EDIT: OK, I finally got it to work :schwitz: I found the way to create a project from existing sources (it wasn't as hidden as I thought, I was just blind), and then I added the common logging JAR, but totally forgot to add the jinsim JAR :D Anyway, after that Eclipse asked me to move "package net.sf.jinsim.examples.helloworld" and so I did. Then I found how to add arguments to the run call, and there I go with my "driver says: Hello World" :thumb:

Gonna try the other examples next!

Starblue
7th July 2008, 10:11
Could anyone post a quick guide on running the Hello World example in Eclipse? It could be very useful for beginners in Java like me to get started :)

Good idea! I love Eclipse but I remember it was quite a pain the first time I used it...trying to understand its many perspective windows and how to import an existing project, libraries and such :)
I'll try to make the tutorial you suggested.


EDIT: OK, I finally got it to work [...]

Gonna try the other examples next!
I'm glad you solved it and.... welcome to Jinsim!! :)

Starblue

bukhem
23rd July 2008, 21:03
Hi!

I just have two quick questions ...

Is this still active? Any changed need for Patch Z?

Is it possible to get the temperature of the wheels? and if so, how? :shrug:

Cheers,
buk

Starblue
23rd July 2008, 23:05
Hi!

I just have two quick questions ...

Is this still active? Any changed need for Patch Z?

Is it possible to get the temperature of the wheels? and if so, how? :shrug:

Cheers,
buk
Yes, I think it's still active...no changes where needed for patch Z.
As for wheel temperatures, Insim&Outsim don't give this info.

bukhem
25th July 2008, 15:12
Hi.

I hope one of you guys has an idea on this ...
I run a dual-head setup here.
The main screen shows LFS, the second screen - an 8" touchscreen - shows my application.

That all works pretty good as long as I dont run LFS in fullscreen mode.
When I do that I don't get any mouse events anymore on the second display.
Running TouchBuddy excatly that is working, I just don't have an idea on how to get the mouse back on the second display ...

So, any thoughts?

Thanks and greetings.

bdshan
15th August 2008, 16:12
This is killing me and to save my life I can't figure out a solution.

I am trying to read a Path file, AS1.pth to be exact. It was going along swimmingly until I need the number of nodes. When I do a readInt() I get a wacky number 536936448, but I know for a fact that AS1 has 288 nodes. Am I using the wrong function call here? Any suggestions?


File pathfile = new File("c:/temp/AS1.pth");
if (!pathfile.exists()) System.exit(0);
FileInputStream fi = new FileInputStream(pathfile);
DataInputStream di = new DataInputStream(fi);
byte[] bLFSPTH = new byte[6];
di.read(bLFSPTH, 0, 6);
String _LFSPTH = new String(bLFSPTH);
// _LFSPTH must match LFSPTH
if (!_LFSPTH.equals("LFSPTH")) System.exit(0);
// version header
byte version = di.readByte();
if (version > 0) System.exit(0);
// revision header
byte revision = di.readByte();
if (revision > 0) System.exit(0);
// number of nodes
int nodes = di.readInt();
...

rheiser
15th August 2008, 16:43
Not JInSim related, but...

I think you're running into a byte ordering problem. The decimal number 536936448 is 0x20010000 in hex. The decimal number 288 is 0x120 in hex. So it looks to me like the least significant bit (LSB) is first. You can try doing this in your code instead of the readInt():


int nodes = di.readByte() + (di.readByte() << 8) +
(di.readByte() << 16) + (di.readByte() << 24);
You'll have to do that with all value types larger that a byte. And you might have to mask the bytes returned from readByte with 0x000000ff (i.e., di.readByte() & 0x000000ff).

If would probably be best to abstract the calculation into a method call for each data type you need, to save typing :)

Try that and see if it works.

bukhem
26th August 2008, 12:57
Hi.

I currently wonder how I can get a list of players that is currently connected.
I'm writing a small app that keeps track of lap and split times and therefor would need a list of existing players when it connects to the LFS-Client.

Thanks for your help. :thumb:

Greetings.

bdshan
26th August 2008, 13:09
After the client connects you can request the list of connections and players.


// request for connection info
client.send(new TinyRequest(Tiny.ALL_CONNECTIONS));
// request for player info
client.send(new TinyRequest(Tiny.ALL_PLAYERS));


After getting the initial list above you need to listen for new connections and players by checking the packet type in your packetReceived and then dealing with the appropriate type (NewConnectionResponse or NewPlayerResponse).

MaKaKaZo
26th August 2008, 13:15
Hi.

I currently wonder how I can get a list of players that is currently connected.
I'm writing a small app that keeps track of lap and split times and therefor would need a list of existing players when it connects to the LFS-Client.

Thanks for your help. :thumb:

Greetings.

This is a generic answer, not JInSim specific. As stated in the insim documentation, at any time you can request info about all connections and players sending an IS_TINY, with the following values (marked in red) in the field SubT:

enum // the fourth byte of IS_TINY packets is one of these
{
TINY_NONE, // 0 : see "maintaining the connection"
TINY_VER, // 1 - info request : get version
TINY_CLOSE, // 2 - instruction : close insim
TINY_PING, // 3 - ping request : external progam requesting a reply
TINY_REPLY, // 4 - ping reply : reply to a ping request
TINY_VTC, // 5 - info : vote cancelled
TINY_SCP, // 6 - info request : send camera pos
TINY_SST, // 7 - info request : send state info
TINY_GTH, // 8 - info request : get time in hundredths (i.e. SMALL_RTP)
TINY_MPE, // 9 - info : multi player end
TINY_ISM, // 10 - info request : get multiplayer info (i.e. ISP_ISM)
TINY_REN, // 11 - info : race end (return to game setup screen)
TINY_CLR, // 12 - info : all players cleared from race
TINY_NCN, // 13 - info : get all connections
TINY_NPL, // 14 - info : get all players
TINY_RES, // 15 - info : get all results
TINY_NLP, // 16 - info request : send an IS_NLP
TINY_MCI, // 17 - info request : send an IS_MCI
TINY_REO, // 18 - info request : send an IS_REO
TINY_RST, // 19 - info request : send an IS_RST
TINY_AXI, // 20 - info request : send an IS_AXI
TINY_AXC, // 21 - info : autocross cleared
};

With TINY_NCN the server will send an IS_NCN packet for each of the connections present (UCIDs).

With TINY_NPL the server will send an IS_NPL packet for each of the players present (PLIDs).

If you are keeping track of both connection IDs and players IDs (you should), you must do both.

Brilwing
26th August 2008, 13:18
I have not tested it, but I think a tiny request will do. e.g. extend the net.sf.jinsim.examples.console.Console example with:

client.send(new TinyRequest(Tiny.ALL_RESULTS));

But when you want to keep track of all players, you must also response when a player connects or leaves, also when he joins the race.

I have done a stats application that tracks the laps over every driver etc.
Here is the source, but I'm currently refactoring this app, so there will be lots of bugs:
https://openbakery.org/svn/repos/trunk/racecontrol/

bukhem
26th August 2008, 15:57
After the client connects you can request the list of connections and players.


// request for connection info
client.send(new TinyRequest(Tiny.ALL_CONNECTIONS));
// request for player info
client.send(new TinyRequest(Tiny.ALL_PLAYERS));
After getting the initial list above you need to listen for new connections and players by checking the packet type in your packetReceived and then dealing with the appropriate type (NewConnectionResponse or NewPlayerResponse).
Thanks, works like expected.

bukhem
27th August 2008, 07:23
Good morning folks.

Is it possible that there is some inconsitent namen of "IDs" in the library?
If I got that right, there are two IDs per player.

1.) The "connection"-ID, given to the player during the connection.
Sometimes this id seems to be refered as getId() or getConnectionId(), depending on the InSimResponse-Class

2.) The "event"-ID, given to the player when he takes part in an event (race,qualy). I'm just guessing here, didn't really check when an "NewPlayerResponse" gets triggered.
This id seems to be refered as getId() or getPlayerId() depending on the InSimResponse-Class

I'd will to prepare some patches against the current HEAD when there is a chance that they will be at least checked. :shrug:
I'd try to add some documentation as well, cause that part seems to be missing in some classes. :tilt:

Greetings.

Brilwing
27th August 2008, 08:06
JInSim is only the Java implementation of the LFS InSim interface, and I think it should work the same way as InSim is described in Scawens documentation.

I understand your problem, with the player id and the connection id, but I don't think that a solution should be part of JInSim.

It would be better to create a new project that is a higher level object oriented api to communicate with LFS and uses JInSim as basis.
For example: When you want the list of all drivers you call a 'List<Driver> getDrivers()' method that returns a list driver object.

bukhem
27th August 2008, 09:10
And the InSim documenation (or Scawen) tells you how to name, or more importantly document, functions in your library? :wtf2:

Brilwing
27th August 2008, 09:42
:banghead:

Sorry, i though you want only one unique id for a driver (combine connection id and player id). I should read the posts more carefully :shy:

If you will create a patch that rename the getId methods and replaces it with a more readable getConnectionId or getPlayerId, then I'm on your site and will include the patch in JInSim.

(Note to me: first read, then think, then write an answer)

bukhem
27th August 2008, 09:50
:banghead:

Sorry, i though you want only one unique id for a driver (combine connection id and player id). I should read the posts more carefully :shy:

If you will create a patch that rename the getId methods and replaces it with a more readable getConnectionId or getPlayerId, then I'm on your site and will include the patch in JInSim.

(Note to me: first read, then think, then write an answer)

:D
Good to read that, I just thought I had pissed off the devs. :x

Ok, I'll try to clear things up a bit and provide some patches.
Are you using Eclipse as IDE?
Any thoughts about switching to SVN? :tilt:

Cheers,
buk

Brilwing
27th August 2008, 10:57
Are you using Eclipse as IDE?

Yes


Any thoughts about switching to SVN?

Not really. I don't see lots of changes coming to JInSim in the near future, so I think CVS is fine for now. (If I'm wrong, I have no problems switching to SVN)

If you provide patches in the future for JInSim it is also very likely that you get access to the source control ;)

RocksGt
30th October 2008, 19:52
Hi!

I'm a completly n00b on InSim and I'm starting with this library as I'm a bit familiar with Java (at least more than I'm with C :nod:)

I'm trying to get some info of time splits and time laps and I'm missing some info.
I've been able (thanks for that nice examples :thumb:) to get a button showing split times, but I would like to show the name (the LFS-World nick) of the player too. I'm capturing the SplitTimeResponse and I see that it have a playerId field, but I don't know how to get the rest of info about that Player... I think I miss a Player VO class or something :schwitz:

If you can tell me how to get all the info about one player via this PlayerId field I would be very pleased :nod:

Thanks a lot in advance and sorry for my crappy english :schwitz:

Brilwing
30th October 2008, 22:21
With the NewPlayerResponse you get the playername, car name, plate, skin etc.


public void packetReceived(InSimResponse response) {
if (response instanceof NewConnectionResponse) {
// here you get the connection id
} else if (response instanceof NewPlayerResponse) {
// here you get the player id and the player name etc.
}
}

RocksGt
31st October 2008, 08:37
With the NewPlayerResponse you get the playername, car name, plate, skin etc.


public void packetReceived(InSimResponse response) {
if (response instanceof NewConnectionResponse) {
// here you get the connection id
} else if (response instanceof NewPlayerResponse) {
// here you get the player id and the player name etc.
}
}


hmmm I've tried that, but maybe I've made something wrong :D
That packet NewPlayerResponse when is supposed to be sent? When a player connects to server? I'm testing my little app via HotLap... then, when I restart a HL that packet is sent again? :shrug:

The app I'm trying to make is a kind of LFS-Lapper... but I'm going slowly so while I learn the basics I'm just testing with HL's on local, not on a server with several players :nod:

P.S: Don't know if this is the correct thread to comment this type of things, maybe I should open another thread requesting help on the problems I find during my develop and kee this one only for the library per se :shrug:

Brilwing
31st October 2008, 11:10
I'm not sure when it is send when you are hotlapping. At an multiplayer race the NewConnectionResponse is send when a player connects (here you get the connection id). When the player leave the pits or the race is restarted, the NewPlayerResponse is send.
I think that the NewPlayerResonse is also send when you start hotlapping, but I have not tested it.

Just output all responses then you'll see what responses are send:

public void packetReceived(InSimResponse response) {
System.out.println(response);
}

RocksGt
31st October 2008, 11:59
I'm not sure when it is send when you are hotlapping. At an multiplayer race the NewConnectionResponse is send when a player connects (here you get the connection id). When the player leave the pits or the race is restarted, the NewPlayerResponse is send.
I think that the NewPlayerResonse is also send when you start hotlapping, but I have not tested it.

Just output all responses then you'll see what responses are send:

public void packetReceived(InSimResponse response) {
System.out.println(response);
}

Nice, thanks a lot!

Then I supposed I may have a Map of the players connected (I'm seriously thinking of having a PlayerVO just for making things easier :scratchch) and then searching on that map with the id to retrieve the PlayerVO containing all the data of the Player.
Then mantaining that Map when a player connects and when a player leaves the server :nod:

Another question (that I've didn't test it yet) it's about buttons... I'm showing split times on buttons, but I don't know how this could work on a multiplayer environment... may I set the button to a playerID for only that player sees the button of his split time and none of the others players?

bdshan
31st October 2008, 13:16
Maybe this will help.


// tracking HashMaps
Map<Byte, Connection> connections = new HashMap<Byte, Connection>();
Map<Byte, Player> players = new HashMap<Byte, Player>();

// handle new connections
if (pck instanceof NewConnectionResponse)
{
if (!connections.containsKey(connid))
{
connections.put(connid, new Connection(connid, ncr.isAdmin(), username));
}
}

// handle new players
if (pck instanceof NewPlayerResponse)
{
if (!players.containsKey(plyid))
{
players.put(plyid, new Player(npr, (Connection)connections.get(connid), b));
}
}


There might be better ways to do this, but this works for me.

Brilwing
31st October 2008, 13:47
About Button with Split times and a PlayerVO object...
I'm currently working on a tool that I call RaceControl, that does this stuff. But it is not stable enough to release it. RaceControl is OpenSource (Apache 2.0 License) so you can investigate my code here: https://openbakery.org/svn/repos/trunk/racecontrol/

The PlayerControl.java class is where I create my Driver object (=PlayerVO).
You can investigate the Board.java class, here I display the last three laps with button to the current driver.

RocksGt
31st October 2008, 19:32
Thanks for the responses, they solved most of my doubts :nod:

Another question... can a single program connect to several LFS-Servers and listen to all of their responses or may I run one execution of my app for each of the servers I want to receive data from? :shrug:

Brilwing
3rd November 2008, 10:01
Another question... can a single program connect to several LFS-Servers and listen to all of their responses or may I run one execution of my app for each of the servers I want to receive data from? :shrug:

It should be doable, but jinsim has no support to identify from which server the packet comes from, so you have to keep track of this by yourself.

RocksGt
21st November 2008, 08:26
I keep working on my little app :nod:

One more doubt... Is there any way to connect to a server by his name. I mean, now I'm connecting by the server IP but it would be much better if I could connect using only the server name. Maybe connecting to the Master Server and asking him to resolve the IP by the name? :shrug:

Thanks a lot, and very good job with JInSim, the more I work with it the more I apreciate the effort you put on it :thumb:

Brilwing
21st November 2008, 08:47
One more doubt... Is there any way to connect to a server by his name. I mean, now I'm connecting by the server IP but it would be much better if I could connect using only the server name. Maybe connecting to the Master Server and asking him to resolve the IP by the name? :shrug:

AFAIK you cannot resolve the IP using the master server, so you need to know the IP adress or the hostname.
You can also use the insim relay. Here you can connect using the server name. You will get all InSim data through the relay, but sending insim request packets is limited. (see RelayClient.java in the jinsim source code)
JInSim also contains an example how to connect to a host via the insim relay.

RocksGt
21st November 2008, 09:04
AFAIK you cannot resolve the IP using the master server, so you need to know the IP adress or the hostname.
You can also use the insim relay. Here you can connect using the server name. You will get all InSim data through the relay, but sending insim request packets is limited. (see RelayClient.java in the jinsim source code)
JInSim also contains an example how to connect to a host via the insim relay.
Yes, I have looked at it already, but the servers I want to connect to are not in the relay system :(

Well, I'll put the IP's in a parameters file and let's hope there will be no need to change it usually :)

RocksGt
21st November 2008, 16:40
More problems :schwitz:

The server I'm trying to connect to is on a host where more servers are running, all with the same IP and each one on a different port.

I can connect to the server passing that port as the InSim port, I mean:

public JInSimClient(String name, String hostname, int port, String adminPassword)
hostname: The IP
port: the port where that actual server is listening

But then it seems I can get no data as the InSim port is another one :schwitz:

I've seen that the Client class have an udpPort, but no way of getting it working...

I've tried (stupid I think but meh... need to try :D) passing IP:port as hostname, but didn't work :(


Any help? :hug:

Brilwing
23rd November 2008, 11:15
I also have multiple hosts running on one machine and this should not be a problem at all. When you have one host running on port 29999 and the other on 29998, and you specify 29999 as port in jinsim, all should be working fine an the communication should all run on the port 29999.

You do not need the udp port for the insim communication, only when you use outgauge and outsim then the udp port is needed as far as i remember.

RocksGt
24th November 2008, 07:54
I also have multiple hosts running on one machine and this should not be a problem at all. When you have one host running on port 29999 and the other on 29998, and you specify 29999 as port in jinsim, all should be working fine an the communication should all run on the port 29999.

You do not need the udp port for the insim communication, only when you use outgauge and outsim then the udp port is needed as far as i remember.
I think the problem is that ports that I want to use in InSim are not open on the firewall / router of the server :doh:

I've asked the server owner to open that ports and today (maybe tomorrow) will test if it's working :nod:

Again, thanks a lot for the support :thumb:

mihu86
18th December 2008, 14:13
Hi!

I've found a little error in ReorderResponse.java:

public void construct(ByteBuffer buffer) throws BufferUnderflowException {
super.construct(buffer);
numberPlayers = buffer.get();
for (int i = 1; i < MAX_PLAYERS; i++) {
playerPositions.add(new Byte(buffer.get()));
}
}

There sould be "int i = 0" in the for loop. If i == 1, then the list will only contain 31 elements (or there should be "<=" instead of "<").

I've written a Class for sending a reorder packet to LFS.
You can find it here: http://mihu86.uw.hu/lfs/SendReorderRequest.java

Mihu

RocksGt
2nd January 2009, 19:07
In a server-side InSim, is there a way to get the host name?

What I'm trying to do is connect to several servers, and mantain a Map of JInSimClient identified by the host name, so when I receive a packet from LFS I can link the host from where the packet is sent :scratchch

Maybe this could be done by the connectionId or something like that, but the responses don't include a field like that I think :shrug:

So the idea is to override the public void packetReceived(InSimResponse response) method in my Client (the one that implements the JInsimClient) and call to my packetProcessor linking the hostName (or some identifier) to get access to the correct client (send messages back to the server, buttons, etc...)

If you can get me a tip it would be very nice :nod:


******** SOLVED **********

Finally I've used an Integer as clientId :)

Each Client (extended JInsimClient) has a clientId. In the main class I read the config file with the host list and I link each client with an Id (starting at 1). Then I keep a static Map<Integer, Client> at the requestProcessor, so when a packet is received each client do this:

public void packetReceived(InSimResponse response) {

RequestProcessor.getInstance().process(response, clientId);

}


So I can get the client from the Map if the process of that packet Type require it :thumb:

Anyway... I think I need to override some methods as the setVisible of Button cause it calls to JInsimClient.getInstance() and in my environment I have several JInsimClients objects...

I don't know if the JInSim have a better method to deal with an multi server app :shrug:

Brilwing
3rd January 2009, 12:40
I don't know if the JInSim have a better method to deal with an multi server app :shrug:
No, JInSim dones not have a code to deal with multiple clients. If you have such code and you would share it, I could include in the future version of JInSim.