Open / Send Multiple Messages Over TCP And Close Connection On Events
Oct 7, 2014
I have a simple method in Java through which I send commands to a machine over TCP. The problem is:
Machine can't accept more than two connections in 20 seconds.
I need to send 15-20 commands to the machine in 3 minutes.
This is my current method which is not working as it should, 2 commands get transmited but third command hangs because of the machine.
void sendCommand(String command) throws IOException {
String ipaddress = "192.168.0.2";
Socket commandSocket = null;
BufferedWriter out = null;
BufferedReader in = null;
BufferedWriter outToDetailFile = null;
[Code] .....
Basically what i need is:
1st: I need to open the connection by calling method
public void openConnection(String ipaddress, String port){
//Code to start the connection
}
2nd: I need to be able to send commands to the connection I have already opened (i will send multiple messages in time period of 5-10 minutes):
public void sendCommand(String message){
}
3rd: Close that connection
public void closeConnection(){
}
View Replies
ADVERTISEMENT
Apr 8, 2014
I'm working on a project that has two separate components. The first is a back end, that will do most of the heavy lifting, the other part is a front end GUI. The GUI will include the back end into it's project as an imported JAR file.
I need to be able to keep these two decoupled, as I might be writing different front ends using the same back end. The challenge in front of me (well one of many) is how to pass messages from the back end to the GUI so I can report things that are happening.
For example, if i call method FOO, FOO might do several different things; connect to a database, divide by zero, solve world hunger. I want to be able to either tie a JTextArea , or another component (or multiple components) to this stack of information, or at the very least, have something listening for this information, and when I see that my back end reports something, my front end is quickly aware of this information, and then I can process it and inform the user of the front end.
It would also be useful to be able to send a message from front end to back end , so perhaps the back end might learn that the front end user is unhappy and would like to stop running the current query.
View Replies
View Related
Nov 30, 2014
I made UpdateInmateDisplayer a Singleton so that I could access it from the private class ButtonHandler. It works to display the first inmate's number on the screen but when I close out the window and click the Book Inmate button in CurInmatesDisplayer again, it only shows a blank window. I've tried adding the components again from the ButtonHandler in CurInmatesDisplayer but it doesn't work.
View Replies
View Related
Oct 3, 2014
I am new to EJB; I am writing EJB (3.1) program in JBoss 7.1 - I am using MySQL DB with JPA. While executing the program, I am facing the Generic JDBCException: Could not open connection. It is happening only for certain tables in the database; but NOT for all tables. My code is able to access few of the tables in the same database. Here is my full stack trace: -
Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
[code]....
View Replies
View Related
Jun 25, 2015
What I have in my tnsnames.ora and verify it all works via sqlplus
CDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cdb1)
[Code] ....
I am trying to get RJDBC to work so I can connect to Oracle from R doing some data analysis..
This connection string works for my local db which I have it running in my Virtual Box
con <- dbConnect(drv, "jdbc:oracle:thin:@//localhost:1521/orcl", "demo", "demo")
However, it does not work when I do it for the remote db that I really need to pull data from...
> con <- dbConnect(drv, "jdbc:oracle:thin:@//ymsdbppr-scan:1522/YMQCTPRD", "user_read", "user_read")
Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], :
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12514, TNS: listener does not currently know of service requested in connect descriptor
View Replies
View Related
Feb 5, 2014
Can you have multiple key events? by that I mean say you press the right arrow key, or a number on the numeric pad, then you press the letter c. does the second key event get fired? and i can catch both events?
View Replies
View Related
Jan 15, 2014
My program has the following requirements.
Several kinds of celebration dates are displayed.
Say Marriage, a new baby is born and so on. Such special dates are not fixed to be once or twice.
Such that a person can have a marriage and a new born baby celebration or both. One of my thoughts was to used several (up to 3). JLabels and JDateChoosers, but it is quite limiting.
How should I design such a component so that it can accommodate several major events of life.
View Replies
View Related
Jun 2, 2014
I'm making a tic tac toe program. Currently I have a welcome screen for my tic tac toe game, once the button is clicked I want the main game to open. I have created two FXML VBox windows created from JavaFX Scene Builder. I want to know how to close the welcome menu and launch the 2nd FXML window.
This 2nd FXML window will have it's own controller where the tic tac toe calculations will be held.
Here is the event listener on when the mouse action is performed on the button
@FXML
private void startGame(ActionEvent event) {
}
View Replies
View Related
Mar 9, 2013
How can I connect to multiple Databases (using @PersistenceContext) using an EJB? Did I need to connect various Entity Managers corresponding to the each database and simply send my Queries?
I am using Glassfish Application Server
Netbeans IDE
Java Derby Database
Oracle Database
Java Persistence API
View Replies
View Related
Aug 30, 2014
I am using itext to create pdf files , i have filtered some records (preferably i can say around 90) which has the option to open pdf for individual record. Now I need to open all the pdf's of filtered records on a single click , without asking for a open dialogue box. How to go about this ??
View Replies
View Related
Feb 27, 2015
I have a question in mind that this is my registration form. I am sending these values from HTML form to server and database. I have question that in my case if I click next to Add Another Mobile no in HTML.then a block is genereated and each time a new name is generated.
My Question is if I click 6 times then 6 name attribute are generated. How can I send and differentiate them on my server side.
Because at their I will use something request.getAttribute("Attr_Name");
But they are same. How to do this?.
View Replies
View Related
Sep 1, 2014
I have created a JSP page, on click of a particular button, the control moves to the servlet "TestServlet".
This is the code under TestServlet:
import java.io.IOException;
import java.io.PrintWriter;
import java.security.Principal;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
[Code]...
Now, I have got a comment saying I should get the database connection from connection pool. And one more issue is that I have used the function System.getProperty("user.name") to get the username which i have logged in. But this code will be run on Unix which will not support this function. Any function where I can get the windows username. There is a function getUserPrincipal(), but this function returns a NULL. How to resolve this.
View Replies
View Related
Jan 11, 2015
I configured a connection pool in tomcat 7. For every database activity I get a connection from the pool. Do I have to close the connection like other regular connection after the database operation is done? If I close the connection will it have any effect on the connection pool?
View Replies
View Related
Jun 11, 2014
I have a small problem with my code that I can't figure out how to make it work the way it is supposed to. The code is supposed to be a game where a user has to guess numbers between 1-1000. The program counts how many times the user tried to guess the number and it displays a certain message if the guess number is less than 10, more than 10 or 10. I was able to write the code using loops. However, the messages will not always get printed on to the screen. The code seems to work fine except for the last part where the messages, "Either you know the secret or you got lucky", "You should be able to do better", "Aha! you know the secret!" are not always displayed like they are supposed to.
import java.util.Scanner;
public class Guess1 {
public static void main(String[] args) {
int secretNumber;
secretNumber = (int) (Math.random() * 999 + 1);
Scanner input = new Scanner(System.in);
int guess;
int replay;
int test;
test=1;
replay=1;
int count=0;
[code]....
View Replies
View Related
Mar 4, 2014
I have the following code that comes directly from the book Core Java vol 1. The last two statements are mine but when I change the last statement's String the message being logged doesn't change. For that manner when I change the level of the last statement the file doesn't update to the correct log level. What am I doing wrong?
Java Code:
public class LogTester
{
public static void main(String[] args)
{
if (System.getProperty("java.util.logging.config.class") == null
&& System.getProperty("java.util.config.file") == null)
[code]....
Forgot to say the file also only logs the old message and level from a previous recompilation
View Replies
View Related
May 25, 2014
I am new to Java/OOP in general, and am trying to implement a multi-threaded system that contains a master thread, and a set of worker threads that are heterogeneous in the work they do. Once they complete the work, the workers indicate to the master by posting the result on to its queue. Here is the problem. The results of each type of work is different, and the master has to process each differently. In C (which I'm familiar with), this can be achieved by having a message type that is a union of all the expected messages, and by using a switch statement.
I thought of doing something similar in Java, by using instance of on each incoming message (each individual message class having been subclassed from a super message class) , and doing switch on that, but it doesn't seem to be the OO way to do things. The only other way I could think of was to implement an abstract method to get the type of each message, and then use the type in a switch statement, or if-then-else. Is there some other Java idiom to do this kind of processing? Also, if this is an acceptable method, why is it superior to using the reflection to find out the message type (instead of using the abstract getType())?
The message types look similar to the code below:
abstract class Message {
abstract String getType();
} class Result1 extends Message {
ResultType1 content;
String getType() {
[Code] ....
View Replies
View Related
Jun 13, 2014
I am using ActiveMq alongwith Spring in my project. I want my queue to be configured to reject the duplicate messages.I tried my level best to do so. I tried googling for the same. but could not get anything.
View Replies
View Related
Mar 1, 2015
I am having issues with a few lines of code and a java.util.UnkownFormaException. Here are the issues:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '1'
at java.util.Formatter.checkText(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at Storm.toString(Storm.java:99)
at StormChaser.DisplayStorms(StormChaser.java:149)
at StormChaser.main(StormChaser.java:55)
I have tried a lot of different things but can't seem to figure it out.
import java.io.*;
import java.util.Scanner;
public class StormChaser {
public static void main(String[] args)
[code]....
View Replies
View Related
Apr 7, 2014
MQ Issue on the Websphere 7.0.0.25 server ..Same Message is getting redelivered again and again and below exception is coming in System out log. And secondly the messages are not getting processed completely.
[4/7/14 12:14:58:616 GMT+05:30] 0000001e LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[4/7/14 12:16:14:738 GMT+05:30] 00000062 LocalExceptio E CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "onMessage" on bean "BeanId(myroj#myEJB.jar#MQMessageReceiverMDB, null)". Exception data: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor77.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)
at com.ibm.ejs.jms.listener.ServerSessionDispatcher.dispatch(ServerSessionDispatcher.java:47)
at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:98)
[code]...
View Replies
View Related
Sep 19, 2014
I am attempting to maintain separate files for different types of "messages" (user messages, field labels/buttons, data values). In this attempt I am trying to get the description of different data values. For example, a UserStatus "A" might be displayed as Active or Activo.
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="defaultEncoding" value="UTF-8"/>
<property name="basenames">
<list>
<value>WEB-INF/locale/messages/messages</value>
<value>WEB-INF/locale/fields/fields</value>
<value>WEB-INF/locale/values/values</value>
</list>
</property>
</bean>
Here are the relevant entries in the values_en_us.properties file:
user.status.A = Active
user.status.I = Inactive
user.status.P = Pending
I would like to build an Enum for each type of value that I can get the localized value from. In the code below, I have hardcoded the values being passed to the get message to reduce the number of variables when trying to debug this.
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Locale;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public enum UserStatusEnum {
[Code] ....
When this code runs, I get the following message:
org.springframework.context.NoSuchMessageException: No message found under code 'user.status.A' for locale 'en_us'.
On this line of code:
description = appCtx.getMessage("user.status.A", null, new Locale("en_us"));
The application is already showing my custom application error messages I have in the messages localized files, but in that case the ApplicationContext is already available. Because I can get to the contents of the messages_en_us.property files, I'm assuming me config is correct. However, the classes that get the messages content are instantiated by Spring.
The Enums are not created by Spring, so my assumption is that I am doing something wrong in how I am getting a handle on the ApplicationContext or how I am using it.
After looking at the appCtx values in debug mode, I can see that the messageSource > basenames does at least contain my configuration data.
[WEB-INF/locale/messages/messages, WEB-INF/locale/fields/fields, WEB-INF/locale/values/values]
Although I don't see the whole filenames with the file extension anywhere or the property file entries.
View Replies
View Related
Jan 18, 2012
I have some data in the database and values can be added on demand. so when ever the value added to the database i need to promt that message to all users which are accessing my website, so how can i acheive this....
View Replies
View Related
Jan 28, 2014
I have one row editable datatable.I have implemented email validation to one of the column where error message must display on blur of email field.This is working fine.I have a dialog with form to be displayed in the same page. Validation is implemented to this form also with on blur event. The dialog validation message gets displayed on blur but along with that the main form also displays the same validation message. This should not happen.
JSF page
<h:form id="lpcForm">
<div id="content">
<p:commandLink id="cmdLinkDelete" value="Delete"
style="font-size:15px;padding-left:15px;" ajax="true"
action="#{lpcBean.deleteRecords}" update=":lpcForm:lpcDataTable" />
[Code] ....
The message with id lpcErrMsg is the one that i am displaying on blur in the main page when email format is wrong.And this message gets displayed with dialog field validation also although i have never referred to this id to be rendered in the dialog.
The message with id lpcDlgMsg is the message that i am displaying inside the dialog with widgetvar dlg on blur.As of now i have implemented blur event validation for the first required field in the dialog.
View Replies
View Related
Apr 24, 2015
So I am trying to finish this assignment I am not sure how to approach the last part of it. Basically, I need to give the drop down menu functions. For example if you press tennis it will give explanation about tennis lessons.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
public class JMenuFrame extends JFrame implements
ActionListener {
private JMenuBar mainBar = new JMenuBar();
[Code] ....
Attached image(s)
View Replies
View Related
Nov 9, 2014
i've got this code that i cant get to work as i want it to. when its exported and i run it the file i wants gets created but when i open the file there is a single number like 999998000001
import java.io.IOException;
import java.io.PrintWriter;
public class mainHej {
public static void main(String arg[]){
[code]...
View Replies
View Related
Jun 30, 2014
I have two questions:
1. I read somewhere that instead of looping through every player (below), you use could Events to do it for you:
for (Player player : this.getPlayers()) {
if (player.getLocation().getX() == 10) {
}
}
I'm not sure as to how to use Events in place of a for loop. I've been thinking on this for days, but I'm still stuck. Any example of using an Event instead of a for loop?
2. Is there any way to accept multiple connections on a server without using a while loop? Maybe use Events to handle the acceptance of connections?
View Replies
View Related
Jul 10, 2014
For every stream that we create for java i/o we write at the end in finally block
finally
{
if(is!=null)
{
is.close();
}
}
It works
my question is as per syntax in if (is!=null) this means that if is means stream contain some value then close it(!=null)
then how it in my opnion it should be like (in logical way)
if stream contain nothing then close it
if(is==null)
{
is.close();
}
I am confuse about working this line
View Replies
View Related