473,395 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

java.io.ioexception:unable to open a device:255 devices are already opened

126 64KB
I'm not able to figure out this error, i have a code which sends time to a micro-controller through ethernet, It works fine for sometime later gives a error java.io.ioexception:unable to open a device:255 devices are already opened can somebody tell me what's the reason to this error and how do we solve it.

i use netbeans 7.2 IDE with framework core java and jpcap for networking.

Below is my code

Expand|Select|Wrap|Line Numbers
  1.  public void sendTime(Packet pack) {
  2.  
  3.         try {
  4.             InetAddress src = null;
  5.             InetAddress dest = null;
  6.             if (pack instanceof IPPacket) {
  7.                 IPPacket ipp = (IPPacket) pack;
  8.                 src = ipp.dst_ip;
  9.                 dest = ipp.src_ip;
  10.             }
  11.             System.out.println("src ip: " + src);
  12.             System.out.println("dest ip: " + dest);
  13.             //obtain MAC address of the default gateway  
  14.  
  15.             EthernetPacket etherSrc = ((EthernetPacket) pack.datalink);
  16.             byte[] gwmac = null;
  17.             gwmac = etherSrc.src_mac;
  18.             System.out.println("dest mac : " + gwmac);
  19.             //Send packet
  20.             JpcapSender sender = JpcapSender.openDevice(devices[index]);
  21.  
  22.             UDPPacket sendPacket = new UDPPacket(1, 9);//UDPPacket(src_port,dest_port);              
  23.  
  24.             /*setIPv4Parameter(int priority, boolean delay_flag, boolean through_flag, boolean realibility_flag, int rsv_typeofservice, boolean rsv_fragmentation reservation flag, boolean dont_fragment flag, boolean more_fragment flag, int offset, int ident, int time to live, int protocol, java.net.InetAddress src, java.net.InetAddress dst) 
  25.              Sets the IPv4 parameters */
  26.  
  27.             sendPacket.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 1010101, 100, IPPacket.IPPROTO_UDP,
  28.                     src, dest);
  29.             // count++;
  30.             // System.out.println("count = "+count);
  31.             String outData = SendTime();
  32.             sendPacket.data = outData.getBytes();
  33.             System.out.println("string sent =" + sendPacket.data);
  34.  
  35.             EthernetPacket ether = new EthernetPacket(); //get ethernet packet
  36.             ether.frametype = EthernetPacket.ETHERTYPE_IP; //set frame type as IP
  37.             //setting src nd dest MAC address
  38.             ether.src_mac = devices[index].mac_address;
  39.             System.out.println("source MAC address =" + ether.src_mac);
  40.             //ether.dst_mac=new byte[]{(byte)0,(byte)6,(byte)7,(byte)8,(byte)9,(byte)10};
  41.             ether.dst_mac = gwmac;
  42.             System.out.println("destination MAC address =" + gwmac);
  43.             //set datalink frame of packet as ether
  44.             sendPacket.datalink = ether;
  45.             sender.sendPacket(sendPacket);
  46.         } catch (UnknownHostException ex) {
  47.             Logger.getLogger(func.class.getName()).log(Level.SEVERE, null, ex);
  48.         } catch (IOException ex) {
  49.             JOptionPane.showMessageDialog(null, ex);
  50.         }
  51.  
  52.  
  53.     }
Expand|Select|Wrap|Line Numbers
  1. public static String SendTime() {
  2.  
  3.         int week;
  4.         Connection con = null;
  5.         StringBuilder outData = new StringBuilder();
  6.         try {
  7.             Calendar currentDate = Calendar.getInstance();
  8.             SimpleDateFormat formatter =
  9.                     new SimpleDateFormat("00yy:MM:dd HH:mm:ss");
  10.             week = currentDate.get(currentDate.WEEK_OF_MONTH);
  11.             String dateNow = formatter.format(currentDate.getTime());
  12.             String date = dateNow.toString();
  13.             //String dateNow = formatter.format((currentDate.getTime()).toString());
  14.             outData.append("%");
  15.             outData.append(date).append(":").append(week).append("$");
  16.             outData.append("#");
  17.             System.out.println("time sent" + outData);
  18.             System.out.println("time sent");
  19.         } catch (Exception e) {
  20.         }
  21.         return outData.toString();
  22.  
  23.     }
Jan 25 '13 #1
0 1512

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Tux | last post by:
Is it possible and does someone try to make driver for Linux in Java, for some USB device? Could Java do that ? I saw jUSB package but it seems that works only with the devices which Linux...
4
by: Mike Dole | last post by:
I'm working on a client - server application based on the 'How to Sockets Server and How to Sockets Client' code from the Visual Basic ..NET Resource Kit. Since I want to be able to send 'big...
18
by: Mickey Segal | last post by:
On comp.lang.java.programmer we are discussing problems created for Java programs by pop-up blockers (in the thread "showDocument blocked by new microsoft pop-up blocker"). Our problem is that...
25
by: wee | last post by:
I've been using Java for a few years now and am just amazed at how many new "technologies" or tools come out all the time (i.e., Struts, Java Server Faces, JMeter, jad, etc.). It is nigh impossible...
8
by: dbaplusplus | last post by:
I worked on web development using java script many many years, so I am now a newbie to javascript. I have a single html page, which is generated dynamically using some programming language. Web...
5
by: Arno | last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the inconvinience Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable...
4
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hello, (sorry to begin with Java in a Python list ;-) in Java, when I want to pass input to a function, I pass "InputStream", which is a base class of any input stream. In Python, I found...
4
lifeisgreat20009
by: lifeisgreat20009 | last post by:
This is what i am getting on running the program......... C:\PROGRA~1\Java\JDK15~1.0\bin>javac Editor.java Note: Editor.java uses or overrides a deprecated API. Note: Recompile with...
3
by: Tomasz J | last post by:
Hello Developers! A lot has been written about Java Script window.open() function and lost session state. But the most recent version of IE seems to handle it correctly. But now I have an...
29
by: s0suk3 | last post by:
Hello, I was hoping to get some opinions on a subject. I've been programming Python for almost two years now. Recently I learned Perl, but frankly I'm not very comfortable with it. Now I want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.