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
I am working on a crawler and I have the following question: it works with simple HTTP requests, but not HTTPS, and I need to make an HTTPS request. I changed the port to 443 and try to send the same request, but I get 400 error. Obviously, I need to change something else, but I do not know what. I open socket and this is how I make the request:
String request
= "GET " + file
+ (file.endsWith("robots.txt") ? " HTTP/1.0\r\n" : " HTTP/1.1\r\n")
// " HTTP/1.1\r\n"
+ "User-Agent: " + CrawlerConfig.USER_AGENT + "\r\n"
// + ((!CrawlerConfig.SAVE_IMAGES) ? "Accept: text/html\r\n" : "")
// + "Accept: text/*\r\n"
+ (file.endsWith("robots.txt") ? "Connection: close\r\n" : "")
+ "Host: " + host + "\r\n" + "\r\n"/*
* + body
*/;
outStream.write(request.getBytes("US-ASCII"));
outStream.flush();
Try to send an OPTIONS request on the resource, needed request headers should be returned, some may be missing.
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();
}
I am trying to send a sms with smslib but It did not send the message, can somebody guide me on this?
this is my code:
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
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.com1", "COM4", 115200, "Huawei", "");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
// Explicit SMSC address set is required for some modems.
// Below is for VODAFONE GREECE - be sure to set your own!
gateway.setSmscNumber("+919825068000");
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();
// Send a message synchronously.
OutboundMessage msg = new OutboundMessage("+524747388616", "que onda como andas!");
Service.getInstance().sendMessage(msg);
System.out.println(msg);
// Or, send out a WAP SI message.
//OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000", new URL("http://www.smslib.org/"), "Visit SMSLib now!");
//Service.getInstance().sendMessage(wapMsg);
//System.out.println(wapMsg);
// You can also queue some asynchronous messages to see how the callbacks
// are called...
//msg = new OutboundMessage("309999999999", "Wrong number!");
//srv.queueMessage(msg, gateway.getGatewayId());
//msg = new OutboundMessage("308888888888", "Wrong number!");
//srv.queueMessage(msg, gateway.getGatewayId());
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();
}
}
}
and my result:
Example: Send message from a serial gsm modem.
SMSLib: A Java API library for sending and receiving SMS via a GSM modem or other supported gateways.
This software is distributed under the terms of the Apache v2.0 License.
Web Site: http://smslib.org
Version: 3.5.1
Modem Information:
Manufacturer: Nokia Corporation
Model: Nokia Internet Stick CS-10
Serial No: 359340022861915
SIM IMSI: ** MASKED **
Signal Level: -53 dBm
Battery Level: 0%
===============================================================================
<< OutboundMessage >>
-------------------------------------------------------------------------------
Gateway Id: *
Message Id: 0
Message UUID: e30f84ad-b083-4956-85ef-16dc89020769
Encoding: 7-bit
Date: Fri Mar 09 13:15:52 CST 2012
SMSC Ref No: null
Recipient: 524747388616
Dispatch Date: null
Message Status: FAILED
Failure Cause: UNKNOWN
Validity Period (Hours): -1
Status Report: false
Source / Destination Ports: -1 / -1
Flash SMS: false
Text: que onda como andas!
PDU data: F17A19F47693C3A0F1BBFD0685DDE4F03C04
Scheduled Delivery: null
===============================================================================
Now Sleeping - Hit <enter> to terminate.
This example has extra line of code about SMSC-number. I have played with this same library and in my code there is not any SMSC - at any line of my code.
It is a suggestion, "if needed", and I certainly believe getting rid of it solves your problem. You most probably don't know what you exactly have to put on it, so better leaving it out. Then modem will not try to do this routing manually to given number but it can make it to the correct, what it knows by SIM settings on the SIM card.
Another thing I would check is that the modem really answers from COM4 port. Although now it seems to do so, because the signal strength is read. But check this always, because every startup of server can map the device to different port. I was at least having this kind of problem on Linux side.
Maybe you have not taken care enough (yet) to the SerialModemGateway constructor arguments, as you left "Huawei" as vendor whereas you use a Nokia device. That parameter is not important but the baud rate is. According to SMSlib documentation, most devices only works properly in a preset/uniq baudrate.
I propose you open other software settings to get or confirm parameters you have used:
baud rate
gateway SMSC number - maybe from Connection history menu according to Nokia user guide
As you get your code from an Huawei example, this example set the gateway SMSC number but this parameter is supposed to be optional for most devices, only Huawei devices may require it. Try a run without gateway.setSmscNumber !
I also invite you to monitor serial port traffic with Portmon for instance and report it here and on SMSlib forum to get support.
Finally, you should ask SMSlib maintainer its option about your device, as it is in the compatibility list (yet)
Following is a sample code I used and tested. You can re-use it.
package com.stackoverflow.smstest;
import java.net.URL;
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.OutboundWapSIMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
public class Main {
public void sendMessage() throws Exception {
OutboundNotification outboundNotification = new OutboundNotification();
System.out.println("Sample of 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", 57600, "Huawei", "E160");
gateway.setInbound(false);
gateway.setOutbound(true);
// gateway.setSimPin("");
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()
+ "%");
// Send a message synchronously.
OutboundMessage msg = new OutboundMessage("+94123456789",
"SMS test: sample message from StackOverflow");
Service srvice = Service.getInstance();
// Service.getInstance().sendMessage(msg);
System.out.println(msg);
// Or, send out a WAP SI message.
OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("+94123456789",
new URL("http://stackoverflow.com/"),
"WAP test: sample message from StackOverflow!");
// gateway.setFrom("chandpriyankara");
// wapMsg.setFrom("chandpriyankara");
srvice.queueMessage(wapMsg);
Service.getInstance().stopService();
}
/**
* Outbound Message informations handler
*
* #author chandpriyankara
*
*/
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[]) {
Main app = new Main();
try {
app.sendMessage();
} catch (Exception e) {
e.printStackTrace();
}
}
}
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.