Go to Post We might just dip the entire bot in a Locktite bath before bagging. - Kevin Ray [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-01-2011, 18:10
alexhenning alexhenning is offline
WPILib Developer
FRC #0348
 
Join Date: Apr 2010
Rookie Year: 2003
Location: MA
Posts: 49
alexhenning will become famous soon enough
Receiving UDP packets on the CRIO

Hi,

I've been trying to receive custom data on port 1130, but I am unable to get a connection. When running the following code on the CRIO, it stops after printing "Opening socket connection." I assume the issue is with ss.acceptAndOpen(). It doesn't crash, it just stops at that point.

Quote:
System.out.println("Opening server socket connection.");
ServerSocketConnection ss = (ServerSocketConnection) Connector.open("socket://:1130");
System.out.println(ss.getLocalAddress());
System.out.println("Opening socket connection.");
StreamConnection sock = ss.acceptAndOpen();
System.out.println("Opening input stream.");
in = sock.openInputStream();
Does anybody no what I'm doing wrong? Has anyone been able to successfully read data off of port 1130 in java.

Thanks for any help.

Last edited by alexhenning : 31-01-2011 at 08:47.
Reply With Quote
  #2   Spotlight this post!  
Unread 30-01-2011, 19:17
sjspry sjspry is offline
Registered User
FRC #1984
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Kansas
Posts: 125
sjspry has a spectacular aura aboutsjspry has a spectacular aura aboutsjspry has a spectacular aura about
Re: Receiving UDP packets on the CRIO

A ServerSocketConnection is TCP, not UDP. You'd be wanting DatagramConnection, which is UDP. Open with

Quote:
Connector.open("datagram://:<port>");
for incoming, and

Quote:
Connector.open("datagram://<ip>:<port>");
for outgoing (I always thought UDP sockets were bidirectional, but I guess J2ME handles it somewhat differently).
Reply With Quote
  #3   Spotlight this post!  
Unread 31-01-2011, 07:03
John Heden John Heden is offline
Registered User
FRC #1073
 
Join Date: Jan 2011
Location: Hollis, NH
Posts: 29
John Heden is an unknown quantity at this point
Re: Receiving UDP packets on the CRIO

Greetings,

I'm attaching a working CRIO C++ example function that we managed to get working the other day. I wish I could help in Java but perhaps this example might help. There is some dialog on this on another thread around what we can/can’t do with this new UDP functionality.

John

Related thread:
http://www.chiefdelphi.com/forums/sh...&highlight=UDP
Reply With Quote
  #4   Spotlight this post!  
Unread 31-01-2011, 08:47
alexhenning alexhenning is offline
WPILib Developer
FRC #0348
 
Join Date: Apr 2010
Rookie Year: 2003
Location: MA
Posts: 49
alexhenning will become famous soon enough
Re: Receiving UDP packets on the CRIO

I had tried datagram before, unfortunately, when I run it I get:

Quote:
[frcrun] [cRIO] javax.microedition.io.ConnectionNotFoundException: The 'datagram' protocol does not exist
[frcrun] [cRIO] at javax.microedition.io.Connector.open(245)
[frcrun] [cRIO] at javax.microedition.io.Connector.open(193)
[frcrun] [cRIO] at javax.microedition.io.Connector.open(177)
[frcrun] [cRIO] at org.usfirst.frc348.BreakoutBox.<init>(BreakoutBox. java:29)
[frcrun] [cRIO] at org.usfirst.frc348.JagBot.<init>(JagBot.java:24)
[frcrun] [cRIO] in virtual method #11 of com.sun.squawk.Klass(bci=53)
[frcrun] [cRIO] at com.sun.squawk.imp.MIDletMainWrapper.main(99)
[frcrun] [cRIO] in virtual method #95 of com.sun.squawk.Klass(bci=25)
[frcrun] [cRIO] at com.sun.squawk.Isolate.run(1506)
[frcrun] [cRIO] at java.lang.Thread.run(231)
[frcrun] [cRIO] in virtual method #47 of com.sun.squawk.VMThread(bci=42)
[frcrun] [cRIO] in static method #3 of com.sun.squawk.VM(bci=6)
Is there something different about the version of J2ME running on the CRIO?
Reply With Quote
  #5   Spotlight this post!  
Unread 31-01-2011, 13:03
derekwhite's Avatar
derekwhite derekwhite is offline
Java Virtual Machine Hacker
no team (FIRST@Oracle)
Team Role: Programmer
 
Join Date: May 2009
Rookie Year: 2009
Location: Burlington, MA
Posts: 127
derekwhite is on a distinguished road
Re: Receiving UDP packets on the CRIO

Which protocols are supported aren't standardized in CLDC. Java on the cRIO supports socket:, serversocket:, and file: protocols currently. Unfortunately it doesn't support datagrams yet.
Reply With Quote
  #6   Spotlight this post!  
Unread 31-01-2011, 15:23
alexhenning alexhenning is offline
WPILib Developer
FRC #0348
 
Join Date: Apr 2010
Rookie Year: 2003
Location: MA
Posts: 49
alexhenning will become famous soon enough
Re: Receiving UDP packets on the CRIO

Thanks for the info. That's very very annoying, do you know if there are any plans to add support for it. We were going to take advantage of the UDP ports for a custom dashboard and breakout box, but we'd rather stay in java.
Reply With Quote
  #7   Spotlight this post!  
Unread 31-01-2011, 21:13
sjspry sjspry is offline
Registered User
FRC #1984
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Kansas
Posts: 125
sjspry has a spectacular aura aboutsjspry has a spectacular aura aboutsjspry has a spectacular aura about
Re: Receiving UDP packets on the CRIO

If you read team update #5 it mentions a TCP port you can take advantage of, it's currently what I'm using. There's really no good reason to be using UDP, seeing as communications are so close (it just ends up making things more complicated, but whatever).

Oh, port should be 1180, just remembered.
Reply With Quote
  #8   Spotlight this post!  
Unread 01-02-2011, 13:51
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Receiving UDP packets on the CRIO

Quote:
Originally Posted by sjspry View Post
There's really no good reason to be using UDP, seeing as communications are so close (it just ends up making things more complicated, but whatever).
Wouldn't that be a better reason to use UDP? If there's less of a chance of dropped packets, why bother with the added overhead of TCP?
Reply With Quote
  #9   Spotlight this post!  
Unread 01-02-2011, 18:51
sjspry sjspry is offline
Registered User
FRC #1984
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Kansas
Posts: 125
sjspry has a spectacular aura aboutsjspry has a spectacular aura aboutsjspry has a spectacular aura about
Re: Receiving UDP packets on the CRIO

Quote:
Originally Posted by Tom Bottiglieri View Post
Wouldn't that be a better reason to use UDP? If there's less of a chance of dropped packets, why bother with the added overhead of TCP?
Because the "overhead" of TCP is barely noticeable (the information density is ~94%, with ~6% left for headers) and really only comes into play when you have a noisy connection, where packets would be missed and therefore resent, and during the initiation of a connection, which you do once. Dropped packets are a non-issue, as well, and wouldn't affect TCP's performance. It happens, but very rarely (comparatively) and in everything I've experienced it's rarely anything but hardware problem.

Besides apparently not being able to use UDP, TCP is generally easier to use, as a stream, than to have to fit everything into a fixed datagram and then unpack it (this is more of a personal choice, though). The only benefit of UDP will be if you are sending time sensitive information, otherwise I see no reason why it would be chosen to use.

It doesn't matter either way. You can do some time tests with TCP vs UDP, if you want.
Reply With Quote
  #10   Spotlight this post!  
Unread 03-02-2011, 20:50
alexhenning alexhenning is offline
WPILib Developer
FRC #0348
 
Join Date: Apr 2010
Rookie Year: 2003
Location: MA
Posts: 49
alexhenning will become famous soon enough
Re: Receiving UDP packets on the CRIO

I was planning on using the camera too, which according to the update is used by the camera. Also, I control data is time sensitive, so UDP seemed sensible.
Reply With Quote
  #11   Spotlight this post!  
Unread 24-02-2014, 14:13
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
Re: Receiving UDP packets on the CRIO

I was looking at the WPILib/CLDC very carefully recently and I noticed that there is a package called com.sun.cldc.jna that specifies several classes to allow for calling native functions from Java. I was wondering if one could make use of vxWorks UDP functions and implement a UDP communication class using native vxWorks calls. I notice that this is what WPILib essentially does with functions like FRC_NetworkCommunication_JaguarCANDriver_sendMessa ge and FRC_NetworkCommunication_JaguarCANDriver_receiveMe ssage. It appears that this is almost like extern'ing in C/C++.

Alex Brinister
Reply With Quote
  #12   Spotlight this post!  
Unread 25-02-2014, 13:50
NotInControl NotInControl is offline
Controls Engineer
AKA: Kevin
FRC #2168 (Aluminum Falcons)
Team Role: Engineer
 
Join Date: Oct 2011
Rookie Year: 2004
Location: Groton, CT
Posts: 261
NotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond repute
Re: Receiving UDP packets on the CRIO

This might be obsolete, as next year Java teams are no longer constrained to Java ME, and can use the full power of Java SE (which supports both TCP and UDP) on the RoboRio.

Don't think it is fruitful to attempt to add functionality to the current system since it will be phased out next season.

Hope this helps,
Kevin
__________________
Controls Engineer, Team 2168 - The Aluminum Falcons
[2016 Season] - World Championship Controls Award, District Controls Award, 3rd BlueBanner
-World Championship- #45 seed in Quals, World Championship Innovation in Controls Award - Curie
-NE Championship- #26 seed in Quals, winner(195,125,2168)
[2015 Season] - NE Championship Controls Award, 2nd Blue Banner
-NE Championship- #26 seed in Quals, NE Championship Innovation in Controls Award
-MA District Event- #17 seed in Quals, Winner(2168,3718,3146)
[2014 Season] - NE Championship Controls Award & Semi-finalists, District Controls Award, Creativity Award, & Finalists
-NE Championship- #36 seed in Quals, SemiFinalist(228,2168,3525), NE Championship Innovation in Controls Award
-RI District Event- #7 seed in Quals, Finalist(1519,2168,5163), Innovation in Controls Award
-Groton District Event- #9 seed in Quals, QuarterFinalist(2168, 125, 5112), Creativity Award
[2013 Season] - WPI Regional Winner - 1st Blue Banner
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:44.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi