send data to running instance - java

Hello I am creating software which allow files to be uploaded, my software has a chat client which will create a instance of a file uploader class, this file uploader class will take the file from the file chooser, convert it to byte and upload it to the sql database. so essentially I have a main chat client which contains a text area for chat to be show in. I have main chat windows which displays contacts. when the user double clicks on a contact the chat client opens up:
private void jList1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (evt.getClickCount() == 2) {
String userID = lbluserID.getText();
String selectedContact = jList1.getSelectedValue().toString();
ChatClient chatClientObject = new ChatClient(selectedContact, userID);
ChatClient.runchatClient(selectedContact, userID);
}
}
within this chat client I have placed a button which allows the selection of the file. the dbconnect class will upload the file to the server, once this is done I need a message to appear in the chat client text area displaying that the file has been uploaded. I have tried to make a instance of the chat client in the dbconnect class and then call a method to output the message how ever this gives me errors. what I really want to do is allow my program to open the chat client for the contact the user clicks on and also be able to return the message to the same chat client instead of creating a new instance.
I hope my question is clear as it is pretty hard to explain.... for example, If i click on "Ben" in the main client a chat client will open for "ben" this chat client contains a text area. when i have finished uploading the file which is done by the dbconnect class I want the string message "file sent" to be returned to the chat I have open with "ben".

you said 'I have tried to make a instance of the chat client in the dbconnect class and then call a method to output the message how ever this gives me errors.'
Don't create new instance of client to send file completion message, you need to be use the same instance that was created at the time of client instantiated. So that at the time of client instantiated 1st time you need to hold that reference in global variable. And call method using this instance to display message.
It could help you.

Related

How to create a Text Channel in Discord Using JDA: Java Discord Api

event.getGuild().createTextChannel("EzDedline_Reminder")
I have used this command for creating a text channel however the Text channel does get created.
I have given the bot administrative powers and added an event listener in the main function and have extended the listener adapter as well.
I do have the power to manage the channel as I am the owner of server.
Moreover, the code after this line is executing perfectly just this line of code is not able to create a new text channel.
event is the command entered by the user to run this function.
I am using JDA 4.2.1
Call queue().
event.getGuild().createTextChannel("ezdedline_reminder").queue();
See Nothing happens when using X and What is a RestAction?.

send email to generic ID in lotus notes using notesFactory in java

Their is a requirement in a project to send emails from java application through lotus notes.
Note: the domino server is installed on client server.
Currently i am able to send email using notesFactory on my local machine.using notes.jar file
Which accesses the user by .nsf by its password.
I.e creating secure connection by password.
And gtting database object by calling
Session.getdatabase(null,"user.nsf")
Its perfectly working.
But for some types of emails the client have shared a generic id...(link) over an email... By clicking on that link the generic mail box opens under active user. In separate tab... Through which we can send emails.
But have not shared their .nsf path or id or password.
It directly opens by clicking on that link.
Now i want to access that generic id in notesfactory session
I tried to keep open that id and then running my code...but still it sends email through active user itself.
And client is not ready to share the id and password details of that user. Not the id file is getting generated in our local machine.
Is their any way to send emails through that id?
If anyone want code i am using..ill share.
But for some types of emails the client have shared a generic
id...(link) over an email... By clicking on that link the generic mail
box opens under active user. In separate tab... Through which we can
send emails.
That does not sound like a "shared id", it sounds more like a mail database with the ACL set to give a group of users access.
When you send an email from within Notes (no matter if it is through the UI or through code), the actual logged in user is used as the sender. It is intentionally by design, to prevent users from spoofing the sender.
There is an unsupported way to fake the sender address, by dropping the email directly into mail.box, but that should only be done by someone know what they are doing.
I wrote a script library several years ago, intended to help sending emails. It includes the ability to set the sender address. You can find it on my blog, it's free to use. But I would not recommend you using it without first understanding what the code is doing.
Here is the relevant part of the code:
Set mailbox = New NotesDatabase(mailservername,"mail.box")
If mailbox.Isopen = False Then
Print "mail.box on " & mailservername & " could not be opened"
Exit Sub
End If
Set me.maildoc = New NotesDocument(mailbox)
Call me.maildoc.ReplaceItemValue("Form","Memo")
Set me.body = New NotesRichTextItem(maildoc,"Body")
Call maildoc.ReplaceItemValue("Principal", me.p_principal)
' If principal is set, we want to fix so mail looks like
' it is coming from that address, need to set these fields
Call maildoc.ReplaceItemValue("From", me.p_principal)
Call maildoc.ReplaceItemValue("Sender", me.p_principal)
Call maildoc.ReplaceItemValue("ReplyTo", me.p_principal)
Call maildoc.ReplaceItemValue("SMTPOriginator", me.p_principal)
Call maildoc.ReplaceItemValue("PostedDate",Now())
If me.p_principal<>"" Then
Call maildoc.Save(True,False) ' Save in mail.box
Else
Call maildoc.Send(True) ' Send mail normally
End If
You use the Principal field to set the sender address.

Online Multipler Games in Java

In Java, is there a way to make a client/server system for a game without having to enter ips (like in Minecraft).
But instead, have it automatically connect the user to a game when he requests to join one (like in Fortnite, or surviv.io).
The only method I current know for client/server is having to give each user a server ip to connect to (like in Minecraft), so I was wondering if I could do it this way.
Thanks in advance.
IMHO, I think in all ".io" games, they are only hiding the registration processing. In my case, the previous game I made had a feature calls "Quick Play".
When a player uses that playing method and first time joins the game, I get his device's ID (for example in Android) then use it as a unique ID for that player in-game (I'm not sure about iOS but you can get that unique value in Android).
You can see the example below:
_on(TEvent.CONNECTION_SUCCESS, args -> {
var connection = Connection.convert(args[0]);
var message = TObject.convert(args[1]);
info("CONNECTION", connection.getAddress());
// Allow the connection login into server (become a player)
String username = message.getString("u");
// Should confirm that credentials by data from database or other services, here
// is only for testing
_playerApi.login(new PlayerLogin(username), connection);
return null;
});
Now when a new user login, he will send his device's ID and I can treat him a new player and make that ID as his name (or making a randomized name for him)
You can see more detail in the link below:
Login Example

Using java to open a web browser on another computer

So, this is a rather unusual question, and I can't find anything else anywhere which has been helpful on how to do this, or if its even possible to do so.
I'm working on a game server wrote in java, and I'm trying to get the users default web browser to open to a specific link, when a command is typed into the chat box and sent to the server.
The current Issue I have is, when a user issues the command, it opens the browser on the host system, and not the players system.
I haven't been able to try any other methods, as I am unable to find any information regarding my specific situation!
#CommandHandlerMethod(accessLevel = EAccessLevel.USER)
public static Object[] vote(final Player player, final String... params) {
try {
Desktop desktop = java.awt.Desktop.getDesktop();
URI oURL = new URI("www.example.com");
desktop.browse(oURL);
} catch (Exception e) {
e.printStackTrace();
}
return AbstractCommandHandler.getAcceptResult("");
}
What I was hoping for via this code, was to open the web browser on the players system to allow them to view a specific webpage, but this has not been the case, and opens it on the server host system.

GCMIntentService onRegistered Method Need to Send Additional Information to My Server In Addition to regId

Building an Android application using Google's GCM service.
I have implemented the onRegistered method in the GCMIntentService class.
The problem is I want to send the email from EditText in my main activity to my server along with the regId. I'm not sure how to get the email from my main activity and use it in the onRegistered method.
I know how to properly get the string from the EditText box within the main activity that's not a problem. It's throwing me off because it's in a separate class.
My end result is I want to send the email they have typed into the EditText and when they click register the email the email they've typed and their regId will be stored in database on my server.
I currently have working code that just stores their regId with a hard coded name in the onRegistered method. Just looking how to get that additional information so I can send it with the regId.
When the user presses the button, you can put the text from the EditText in a:
file
database
SharedPreferences
static data member
and then retrieve the text from that location in onRegistered().

Categories

Resources