|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Java and C++ integration, UDP/TCP
I have written the skeleton of my vision code in C++ now. That runs on the Driver station computer parallel to all the FMS tasks. Our robot is coded in Java. To bring these together, C++ => Java, DS => cRIO, I am thinking about using network sockets.
I would prefer to use UDP because it is faster, but as I've heard, the UDP implementation is either non-existent or doesn't function well in Java, so TCP can work. I'm persuading the rest of the programming team to work on a small socket client, but they probably either don't understand network sockets or they aren't showing GP. How is the socket networking done with Java on the cRIO? I could use that as a starting point for getting the rest of the programmers to understand what I'm trying to do! |
|
#2
|
||||
|
||||
|
Re: Java and C++ integration, UDP/TCP
I only have a basic understanding of all of this myself, but this idea is very interesting. A quick google search revealed this website on java networking. It talks about the basic ideas of networking as well as how to implement it in java.
I also found the open ports on the field here. It looks like you could be TCP 1180 or HTTP 80/443 depending on your camera configuration. If you wanted to use java on both ends, I have had great success with Netty. |
|
#3
|
||||
|
||||
|
Re: Java and C++ integration, UDP/TCP
What about UDP/TCP 1234, etc. Does it mean that that port is blocked?
|
|
#4
|
||||
|
||||
|
Re: Java and C++ integration, UDP/TCP
I read it as only the ports listed are available for use.
|
|
#5
|
||||
|
||||
|
Re: Java and C++ integration, UDP/TCP
Quote:
Quote:
Code:
SocketConnection sc = (SocketConnection) Connector.open("socket://10.xx.yy.5:1180");
sc.setSocketOption(SocketConnection.LINGER, 5);
InputStream is = sc.openInputStream();
OutputStream os = sc.openOutputStream();
os.write("\r\n".getBytes());
int ch = 0;
while(ch != -1) {
ch = is.read();
}
is.close();
os.close();
sc.close();
Last edited by Domenic Rodriguez : 11-02-2014 at 12:55. Reason: Added more info |
|
#6
|
||||
|
||||
|
Re: Java and C++ integration, UDP/TCP
We go TCP all the way. We have our own specific reasons, most stemming from the mentors' careers in critical applications where reliability trumps speed.
UDP is only faster because doesn't have QoS built in. This means you may only get part of the message back to the robot, which may not handle a bad message and crash. It also doesn't natively enforce FIFO messaging, so the messages may collide or come out of order. This is fine if your robot is trying to tweet something - but maybe not so much for that critical vision target message. First 4-bytes are the 'magic number'; second 4-bytes are the message length; the third 4-bytes are the robot time stamp; then finally the message itself. The 12-byte custom header is well-worth the overhead when considering how easy it is to implement a new message. The message encode/decode order is hard-coded to reduce dependencies on external 'flavor of the month' libraries, but is generally easier to do than it seems on the surface. The design approach also teaches students the basics of network programming. We have different messages: one is the data, one is debug messaging, others are more custom. The debug messages have the same format but are arrays of 2-byte chars, making it very easy to dump to and yank off of the socket. The robot is C++, our custom driver's display & vision system is Java. It wasn't trivial to setup and integrate (threading on the robot mainly), but now it works flawlessly. I plan to release a more generic library over the summer for use with next year's control system. Can't wait for a Linux-based flavor of robot ![]() Last edited by JesseK : 11-02-2014 at 18:35. |
|
#7
|
|||
|
|||
|
Re: Java and C++ integration, UDP/TCP
I would recommend you also take a look at NetworkTables. Integrating C++ into NetworkTables on the drive station will take some use of magic Java stuff called JNI - Java Native Interface. Search here in ChiefDelphi to get some hints.
Best, Martin Haeberli (one of many) Mentor(s) to FRC Team 3045 - SWAT - San Mateo, CA |
|
#8
|
|||
|
|||
|
Re: Java and C++ integration, UDP/TCP
I recommend not just to use UDP, but to use UDP only and nothing more. Do not use TCP and UDP together - better learn how to implement those TCP features based on UDP you may require instead.
Last edited by KunlerOte : 12-02-2014 at 09:36. |
|
#9
|
||||
|
||||
|
Re: Java and C++ integration, UDP/TCP
I just asked our programming mentor and he told me he knew how to implement it! Now, I need to learn the C++ side! Can I use winsock.h/winsock2.h? I don't know how Java uses the network (the packets it sends) and how to use that with C++. If it can run in Linux too, that would be greatly appreciated!
![]() |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|