0

Is it possible to disconnect from one wi-fi network and connect to another network programatically using java?

My java application makes request to twitter using twitter4j. I can make only 350 requests per hour from a particular IP address. Now I'm sleeping for an hour before continuing my requests. But I have two Wi-Fi networks to connect to.

So when the limit exceeds and I get an exception, if I can switch between the networks, I can double the amount of work done. Is it possible in java?

haylem
  • 22,460
  • 3
  • 67
  • 96
Balaji
  • 123
  • 1
  • 7

2 Answers2

0

It's only possible in java because java can call native code. You would need to implement this with native code in C or C++.

Rocky Pulley
  • 22,531
  • 20
  • 68
  • 106
  • Thanks Rocky, I'll now look up how to do this using C/C++ – Balaji Jun 13 '12 at 18:45
  • @Balaji: Why event do that? You can most likely re-use an existing system program with less code to fork, if you don't care about portability. (not saying Rocky's answer is wrong, it's right in every way, but you may be going down a harder road than necessary). – haylem Jun 13 '12 at 19:17
  • 1
    @haylem - You are absolutely right - I'm going to write a shell script with commands to to connect to a new network and call that from my java program. Commands to connect to a wireless network was found from here http://askubuntu.com/questions/138472/how-do-i-connect-to-a-wpa-wifi-network-using-the-command-line – Balaji Jun 14 '12 at 20:01
0

You could execute from your Java program an external program that would disconnect and reconnect (if you get an IP via DHCP).

Doesn't seem like the solution lies in the program, though. More in the way it's being used... or what it's being used (or shouldn't be used) for.

haylem
  • 22,460
  • 3
  • 67
  • 96