I have successfully implemented signalR client for android but my problem is to get return data from server. I can able to send messages from side and it is showing at other client when i am broadcasting but i am not getting the message.
Can anybody help me how to get messages by hubproxy.on method.
String host = "serverlink";
connection = new HubConnection(host);
hub = connection.createHubProxy("myHub");
hub.subscribe(MainActivity.this);
hub.on("addChatMessage", new SubscriptionHandler() {
#Override
public void run() {
// TODO Auto-generated method stub
System.out.println("test");
}
});
// connection.start();
SignalRFuture<Void> awaitConnection = connection.start();
try {
awaitConnection.get();
} catch (InterruptedException e) {
System.out.println("<<<Exception>>>" + e.toString() + "<<<>>>"
+ e.getMessage());
} catch (ExecutionException e) {
System.out.println("<<<Exception>>>" + e.toString() + "<<<>>>"
+ e.getMessage());
}
joinButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try {
hub.invoke("InformUserName", joinEditText.getText().toString()).get();
} catch (InterruptedException e) {
System.out.println("<<<Exception>>>" + e.toString()
+ "<<<>>>" + e.getMessage());
} catch (ExecutionException e) {
System.out.println("<<<Exception>>>" + e.toString()
+ "<<<>>>" + e.getMessage());
}
}
});
sendButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try {
hub.invoke("Send", joinEditText.getText().toString(), messEditText.getText().toString()).get();
} catch (InterruptedException e) {
System.out.println("<<<Exception>>>" + e.toString() + "<<<>>>"
+ e.getMessage());
} catch (ExecutionException e) {
System.out.println("<<<Exception>>>" + e.toString() + "<<<>>>"
+ e.getMessage());
}
}
});
hub.on is Not Calling how can i initialise subcriptionhandler
Related
When playing audio using XamarinMediaManager nuget on xamarin ios, the audio is very soft even though the volume is set to maximum. This nuget package works perfectly fine for android.
I have a global variable for the player set on page load:
public IMediaManager NewPlayer { get; set; }
public AudioPage()
{
try
{
InitializeComponent();
NewPlayer = CrossMediaManager.Current;
NewPlayer.MediaItemFinished += NewPlayer_MediaItemFinished;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
DisplayAlert("Error", ex.ToString(), "Ok");
}
}
When the screen loads, the audio file is loaded to the player:
public async void SetAudioPlayer(string AudioPath)
{
try
{
if (File.Exists(AudioPath))
{
if (NewPlayer.Queue.Count > 0)
{
NewPlayer.Queue.Clear();
}
var generatedMediaItem = await CrossMediaManager.Current.Extractor.CreateMediaItem(AudioPath);
// Add media item to queue
NewPlayer.Queue.Add(generatedMediaItem);
}
}
catch (Exception ex)
{
await DisplayAlert("Error", ex.ToString(), "Ok");
}
}
This is the code for when the play button is clicked:
private async void imgPlay_Clicked(object sender, EventArgs e)
{
try
{
if (NewPlayer.Queue.MediaItems.Count > 0)
{
if (Device.RuntimePlatform == Device.iOS)
await NewPlayer.PlayQueueItem(CrossMediaManager.Current.Queue.MediaItems.Count - 1);
else
await NewPlayer.Play();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
await DisplayAlert("Error", ex.ToString(), "Ok");
}
}
I have a RXTX project that I'm working on. I have it set ups as follows:
public void doConnect(ActionEvent event)
{
String selectedPort = (String)connectTabController.portList.getValue();
System.out.println("Connecting to: " + selectedPort);
selectedPortIdentifier = (CommPortIdentifier)portMap.get(selectedPort);
CommPort commPort = null;
try
{
commPort = selectedPortIdentifier.open("AT QC ReponseTime", TIMEOUT);
serialPort = (SerialPort)commPort;
setConnected(true);
if (isConnected)
{
if (initIOStream() == true)
{
initListener();
System.out.println("Initializing listener");
connectTabController.gui_changeStatusLabel("Device Connected!");
}
}
}
catch (PortInUseException e)
{
System.out.println("Port In use! " + e.toString());
}
catch (Exception e)
{
System.out.println("Failed to open! " + e.toString());
}
}
public boolean initIOStream()
{
//return value for whether opening the streams is successful or not
boolean successful = false;
try {
//
input = serialPort.getInputStream();
output = serialPort.getOutputStream();
writeData(RESETTPOD);
System.out.println("Writing Reset command");
successful = true;
System.out.println("IO Stream opened successfully!");
return successful;
}
catch (IOException e) {
System.out.println("I/O Streams failed to open. (" + e.toString() + ")");
return successful;
}
}
public void initListener()
{
try
{
serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
}
catch (TooManyListenersException e)
{
System.out.println("Too many listeners. (" + e.toString() + ")");
}
}
That's how the connection is made, and it has a listener that's supposed to notify when data is available, which triggers the following:
#Override
public void serialEvent(SerialPortEvent evt) {
BufferedReader reader = null;
if (evt.getEventType() == SerialPortEvent.DATA_AVAILABLE)
{
try
{
reader = new BufferedReader(new InputStreamReader(input));
if (reader.ready())
{
fullLine = reader.readLine();
System.out.println(fullLine + "\n");
}
}
catch (Exception e)
{
System.out.println("#SerialEvent Failed to read data. (" + e.toString() + ")");
}
}
}
However, I keep getting "UNDERLYING INPUT STREAM RETURNED ZERO BYTES"
This makes no sense, since if there is nothing to read then the listener shouldnt be triggered int he first place. I tried running the app and I keep getting this error message around every 1/3 second, which corresponds to the burst-output of the device that's sending data. (which works fine in programs like PuttY)
If you are going to use the BufferedReader, take a look at the refence API document for javax.comm, CommPort and getInputStream. Then try using different settings for threshold and receive timeout.
eg).
serialPort.enableReceiveThreshold(3);
serialPort.enableReceiveTimeout(1);
https://docs.oracle.com/cd/E17802_01/products/products/javacomm/reference/api/
Hello,
I can't find out how to make it so i can save data to a txt. It works while I'm in eclipse but not when i export as a runnable Jar File.
My code is:
public void openFile()
File file = new File(System.getProperty("user.dir"), "src/save/Kube.txt");
FileWriter fw = null;
try {
fw = new FileWriter(file.getAbsoluteFile());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
x = new BufferedWriter(fw);
}
public void addRecords() {
try {
x.write(game.getTotalCoins() + "\n");
x.write(game.getHighScore() + "\n");
x.write(game.getBackround() + "\n");
x.write(game.getCube() + "\n");
x.write(game.isBlackselected() + "\n");
x.write(game.isBlueselected() + "\n");
x.write(game.isGreenselected() + "\n");
x.write(game.isBlueunlocked() + "\n");
x.write(game.isGreenunlocked() + "\n");
x.write(game.isDefaultselected() + "\n");
x.write(game.isSkyselected() + "\n");
x.write(game.isUnderwaterselected() + "\n");
x.write(game.isSkyunlocked() + "\n");
x.write(game.isUnderwaterunlocked() + "");
} catch (IOException e) {
e.printStackTrace();
}
}
public void closeFile() {
try {
x.close();
} catch (IOException e) {
e.printStackTrace();
}
}
When ran in eclipse it works fine but when made into runnable jar file does not save.
Thanks for your help!
I am trying to use jgit to pull the changes from a git repository.
I am facing minor issues with HEAD DETACHED error when I do a pull
I have read other answers here on stackoverflow. Trying those solutions does not seem to help.
I have 2 remote branches
1. staging
2. master
Here is the sample code:
public static void main(String [] args){
final String GIT_STR = "https://github.com/newlifer2/testNewLiferRepo.git";
final String localRepositoryPath = new File("").getAbsolutePath() + File.separatorChar;
try{
//setting up local repository as just testNewLiferRepo
String repoName = localRepositoryPath + "testNewLiferRepo";
File f = new File(repoName);
Repository localRepo = new FileRepository(repoName + File.separatorChar + ".git");
ObjectId oldObjid = null;
Git git = null;
if (f.exists()) {
oldObjid = localRepo.resolve(Constants.HEAD);
git = Git.open(f);
git.pull().call();
ObjectId currentObjid = localRepo.resolve(Constants.HEAD);
git.getRepository().close();
} else {
git = Git.cloneRepository().setURI(GIT_STR).setDirectory(new File(repoName)).call();
ObjectId currentObjid =localRepo.resolve(Constants.HEAD);
if(!localRepo.getBranch().equalsIgnoreCase("staging")){
git.checkout().setName("refs/remotes/origin/staging").setForce(true).call();
}
git.getRepository().close();
}
} catch (InvalidRemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransportException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RevisionSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AmbiguousObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IncorrectObjectTypeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
You can update the version in the testXML file on the repository to test the pull.
Any pointers are highly appreciated
Thanks
Looks like I had my statements switched. Here is a new solution
public static void main(String [] args){
final String GIT_STR = "https://github.com/newlifer2/testNewLiferRepo.git";
final String localRepositoryPath = new File("").getAbsolutePath() + File.separatorChar;
SSHSessionFactory sessionFactory = new SSHSessionFactory();
sessionFactory.Initialize();
SshSessionFactory.setInstance(sessionFactory);
try{
//setting up local repository as just testNewLiferRepo
String repoName = localRepositoryPath + "testNewLiferRepo";
File f = new File(repoName);
Repository localRepo = new FileRepository(repoName + File.separatorChar + ".git");
ObjectId oldObjid = null;
Git git = null;
if (f.exists()) {
oldObjid = localRepo.resolve(Constants.HEAD);
git = Git.open(f);
Map<String,Ref> m = git.getRepository().getAllRefs();
System.out.println("Current Branch: "+git.getRepository().getBranch());
if(git.getRepository().isValidRefName("refs/remotes/origin/staging")){
System.out.println("Valid");
}
git.pull().call();
git.checkout().setName("staging").call();
ObjectId currentObjid = localRepo.resolve(Constants.HEAD);
git.getRepository().close();
} else {
git = Git.cloneRepository().setURI(GIT_STR).setDirectory(new File(repoName)).call();
ObjectId currentObjid =localRepo.resolve(Constants.HEAD);
if(!localRepo.getBranch().equalsIgnoreCase("staging")){
git.branchCreate().setForce(true).setName("staging").setStartPoint("refs/remotes/origin/staging").call();
}
git.checkout().setName("staging").call();
git.getRepository().close();
}
} catch (InvalidRemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransportException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RevisionSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AmbiguousObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IncorrectObjectTypeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I have ABC.action which invokes the doFilter method of Filter Class which is configured properly in web.xml
I need to find action name from request object. How can i achieve this?
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws IOException, ServletException {
long t1 = System.nanoTime();
filterChain.doFilter(request, response);
long t2 = System.nanoTime();
long time = t2 - t1;
// Just writing statistics to servlet's log
System.out.println("## " +
"ArriveTime ns " + t1 + " Departtime ns " + t2 + " ServiceTime : " + time);
// System.out.println("Time taken to process request to "
// + ((HttpServletRequest) request).getRequestURI()
// + ": " + totalTime + " ms.");
}
Try below code(working in JBOSS).
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain fc) throws IOException, ServletException {
System.out.println("Request");
System.out.println(req);
// req instance of HttpServletRequest
if (req instanceof HttpServletRequest) {
HttpServletRequest httpReq = (HttpServletRequest) req;
System.out.println(httpReq.getRequestURI());
} else {
// req is not instance of HTTPServletRequest then try reflection
try {
Class clazz = Class
.forName("org.apache.catalina.connector.RequestFacade");
Method method = clazz.getMethod("getContextPath", new Class[0]);
String actionName = (String) method.invoke(req, new Object[0]);
System.out.println(actionName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}