Connect to program's hotspot programmatically - java

In my program there is two ability
create hotspot
connect to this hotspot
I install this program on two different device. a Samsung gallaxyS2 and a HTC oneM8 . there is no problem in creating hotspot .if I create hotspot on Samsung gallaxyS2 ,I can connect to it with HTC oneM8 easily , but if I create hotspot on HTC oneM8 and try to connect with Samsung gallaxyM8 , the addNetwork Function return -1 .
this is my connecting code :
private void JoinToNetWork(){
ScanResult AP= scanAP();
if (AP!=null){
try{
txt.setText("Hotspot named ''" + AP.SSID +"'' is found ! \n");
wConfig=new WifiConfiguration();
wConfig.SSID=AP.SSID;
wConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
wConfig.allowedAuthAlgorithms.clear();
wConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
wConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
int NetId=wfMgr.addNetwork(wConfig);
try{
txt.append("Disconnect : " + wfMgr.disconnect() +"\n");
txt.append("Enabling network ... " + wfMgr.enableNetwork(NetId, true) + "\n");
txt.append("Reconnect to " + AP.BSSID + "/" + AP.SSID + ".... " + wfMgr.reconnect() + "\n");
wfMgr.setWifiEnabled(true);
txt.append("connected");
}catch(Exception e){
txt.setText(e.toString());
}
}catch(Exception e){
Toast.makeText(this.getBaseContext(), e.getMessage()+"..."+e.toString(),Toast.LENGTH_LONG).show();
}
}else
Toast.makeText(this.getBaseContext(), "There is no BluffGame AccessPoint",Toast.LENGTH_LONG).show();
}

Related

JDA - VoiceChannel#getMembers() isn't returning voice users

I want to iterate through my discord's voices channels and get their members.
But my code (below) isn't working as expected.
for (VoiceChannel voiceChannel : event.getJDA().getGuildById(Config.guildId).getVoiceChannelCache()) {
System.out.println("-> " + voiceChannel.getName() + " -->> " + voiceChannel.getMembers().size());
}
However I put it after a ReadyEvent, so I don't know why it isn't working

actian JCL example

Does anyone have an example of retrieving data using Actian's JCL to a loosely coupled pervasive database in Java? The database I am connecting to only has DAT files. My goal is to create a link between pervasive and MS SQL.
I am not looking for a freebie, but someone to point me in the right direction so I can learn and grow.
Thank you in advanced!
Found this in my archives. Don't know when it was written, whether it works, or if this interface is still supported. You don't say what version of PSQL you're using so I don't even know if this will work with your version.
import pervasive.database.*;
public class VersionTest implements Consts
{
public VersionTest()
{
try
{
Session session = Driver.establishSession();
Database db = session.connectToDatabase("PMKE:");
XCursor xcursor = db.createXCursor(57000);
//Using local TABL.DAT (length 255 assures no leftovers!)
xcursor.setKZString(0,255,"plsetup\\tabl.dat");
//Open the file to load local MKDE
int status = xcursor.BTRV(BTR_OPEN);
System.out.println("Local Open status: " + status);
//Using remote TABL.DAT (length 255 assures no leftovers!)
xcursor.setKZString(0,255,"h:\\basic2c\\develop\\tabl.dat");
//set the buffer size
xcursor.setDataSize(15);
//get version
status = xcursor.BTRV(BTR_VERSION);
System.out.println("Version status: " + status);
// should be 15, always prints 5
System.out.println("Version length: " + xcursor.getRecLength());
System.out.println("Version: " + xcursor.getDString(0,15));
// try with an open file on a server
XCursor xcursor2 = db.createXCursor(57000);
//Using remote TABL.DAT (length 255 assures no leftovers!)
xcursor2.setKZString(0,255,"h:\\basic2c\\develop\\tabl.dat");
//Open the file
status = xcursor2.BTRV(BTR_OPEN);
System.out.println("Remote Open status: " + status);
//set the buffer size
xcursor2.setDataSize(15);
//get version
status = xcursor2.BTRV(BTR_VERSION);
System.out.println("Version status: " + status);
// should be 15, always prints 5
System.out.println("Version length: " + xcursor2.getRecLength());
System.out.println("Version: " + xcursor2.getDString(0,15));
// clean up resources
Driver.killAllSessions();
}catch(Exception exp)
{
exp.printStackTrace();
}
}
public static void main(String[] args)
{
new VersionTest();
}
}
JCL APIs are still supported with Actian PSQL v12 and v13.
You can find more documentation on retrieving data using Actian JCL at
http://docs.pervasive.com/products/database/psqlv12/wwhelp/wwhimpl/js/html/wwhelp.htm#href=jcl/java_api.2.2.html
To link to MS Sql Server you would need to create the data dictionary files(DDFs) for the PSQl data files to use with relational interfaces.

org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException

I am trying to send messages using smslib api and to be honest i have very little info about it so i download a sample project and put the libs in respective places as told . My class to send messages is :
public class SendMessage{
public void doIt() throws Exception
{
OutboundNotification outboundNotification = new OutboundNotification();
System.out.println("Example: Send message from a serial gsm modem.");
System.out.println(Library.getLibraryDescription());
System.out.println("Version: " + Library.getLibraryVersion());
SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 9600, "", "");
gateway.setInbound(true);
gateway.setOutbound(true);
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
System.out.println();
System.out.println("Modem Information:");
System.out.println(" Manufacturer: " + gateway.getManufacturer());
System.out.println(" Model: " + gateway.getModel());
System.out.println(" Serial No: " + gateway.getSerialNo());
System.out.println(" SIM IMSI: " + gateway.getImsi());
System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();
OutboundMessage msg = new OutboundMessage("contact_num", "Hello from SMSLib!");
Service.getInstance().sendMessage(msg);
System.out.println(msg);
System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
Service.getInstance().stopService();
}
public class OutboundNotification implements IOutboundMessageNotification
{
public void process(AGateway gateway, OutboundMessage msg)
{
System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
System.out.println(msg);
}
}
public static void main(String args[])
{
SendMessage app = new SendMessage();
try
{
app.doIt();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
on executing the line
Service.getInstance().startService();
I get an exception :
org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
at org.smslib.Service$1Starter.run(Service.java:277)
Well this had to occur because i don't have a GSM Modem so i have a few questions.
Can i turn my android phone into gsm modem.
What does modem.com4 in SerialModemGateway("modem.com4", "COM4", 9600, "", ""); mean .
I searched a lot on how to turn my phone into a gsm modem but no luck.
for Question#1 : Yes, I think you can do it.
for Question#2 (To get the COM port): Which OS you are using ? for Windows -
Just install your cellphone drivers and then connect your mobile to PC. (Usually there are drivers in the mobile packages disks.)
Then open "Phone and Modem" from your windows control panel.
Then click on "Modems" tab. Now you can see all of your modems and their COM number.
Use your cellphones's COM port in your application.
If you can not see your cellphones name as a modem in "Phone and Modem", it mean that you can not use your cellphone as a GSM modem.

Xmpp OutgoingFileTransfer stopps with Status= Refused

I try to send a File via xmpp and smack
FileTransferManager manager = new FileTransferManager(
this.xmppConnection);
OutgoingFileTransfer transfer = manager
.createOutgoingFileTransfer(this.jid);
transfer.sendFile(file, "test");
while (!transfer.isDone()) {
LOGGER.info("Uploading File: " + file.getName() + " STATUS: "
+ transfer.getStatus() + " >> progress: " + 100
* transfer.getProgress());
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
LOGGER.error("Exception: " + ex);
}
}
LOGGER.info("File transfer is done: " + file.getName() + " STATUS: "
+ transfer.getStatus() + " >> progress: " + 100
* transfer.getProgress());
LOGGER.info("Amount written: " + transfer.getAmountWritten());
LOGGER.info("Bytes sent: " + transfer.getBytesSent());
LOGGER.info("Peer: " + transfer.getPeer());
LOGGER.info("Error: " + transfer.getError());
LOGGER.info("Exception: ", transfer.getException());
The logs are:
Uploading File: image_P9.png STATUS: Initial >> progress: 0.0
Uploading File: image_P9.png STATUS: Negotiating Transfer >> progress: 0.0
File transfer is done: image_P9.png STATUS: Refused >> progress: 0.0
Amount written: -1
Bytes sent: -1
Peer: felix.infraview#jabber.de/IM+ Android
Error: null
Exception:
so I don't get a Error or Exception. The sending is just refused.
My goal is to send an inline-image to any android client.
STATUS: Refused
...
Peer: felix.infraview#jabber.de/IM+
It means the target peer does not support file transfer methods you offer to. XMPP SI File Transfer is a very complex specification which is not implemented by simple clients.
In fact, it does not properly implemented in Smack too, they can give you detailed description about error, but implemented only generic "refused".

Why do the outputs differ when I run this code using NetBeans 6.8 and Eclipse? [duplicate]

This question already has an answer here:
Closed 12 years ago.
Possible Duplicate:
Why do the outputs differ when I run this code using NetBeans 6.8 and Eclipse?
When I am running the following code using Eclipse and NetBeans 6.8. I want to see the available COM ports on my computer. When running in Eclipse it is returning me all available COM ports, but when running it in NetBeans, it does not seem to find any ports ..
public static void test() {
Enumeration lists=CommPortIdentifier.getPortIdentifiers();
System.out.println(lists.hasMoreElements());
while (lists.hasMoreElements()) {
CommPortIdentifier cn =
(CommPortIdentifier)lists.nextElement();
if ((CommPortIdentifier.PORT_SERIAL==cn.getPortType())) {
System.out.println(
"Name is serail portzzzz " +
cn.getName()+
" Owned status " +
cn.isCurrentlyOwned());
try {
SerialPort port1=(SerialPort)cn.open("ComControl",800000);
port1.setSerialPortParams(
9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
System.out.println("Before get stream");
OutputStream out=port1.getOutputStream();
InputStream input=port1.getInputStream();
System.out.println("Before write");
out.write("AT".getBytes());
System.out.println("After write");
int sample=0;
//while((( sample=input.read())!=-1)){
System.out.println("Before read");
//System.out.println(input.read() + "TEsting ");
//}
System.out.println("After read");
System.out.println(
"Receive timeout is " +
port1.getReceiveTimeout());
}
catch(Exception e) {
System.err.println(e.getMessage());
}
}
else {
System.out.println(
"Name is parallel portzzzz " +
cn.getName() +
" Owned status " +
cn.isCurrentlyOwned() +
cn.getPortType() +
" ");
}
}
}
Output with Netbeans,
false
Output using Eclipse,
true
Name is serail portzzzz COM1 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail portzzzz COM2 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is parallel portzzzz LPT1 Owned status false2
Name is parallel portzzzz LPT2 Owned status false2
An initial guess would be that the library you use use native code enclosed in a DLL and that code cannot be found giving an error earlier you have missed, and the code falls back to a dummy behaviour.
I would have a closer look at the initialization code to see what happens there.

Categories