Amruta Jegarkal

Greenhorn
+ Follow
since Nov 29, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Amruta Jegarkal

Winston Gutkowski wrote:

Amruta Jegarkal wrote:I already did this much...


Just for future reference, that's a heck of a lot of information to leave out.

Now...what was your question again? Have you run this? Does it compile? If you've run it, does it produce an error?

We're really floundering in the dark until you tell us what your specific problem is.

Winston


This code is working fine,my question is when server sends something to client;until client reply server cannot send anything.....So i want client and sever to be independent in sending message.
11 years ago

Lukasz Jarocki wrote:Well, show some effort, nobody won't write whole code. Just show which part of implemantation is difficult for you.

Basicaly all you need to do (on server side) is:
- create server socket and bind it
- wait for connection (accept method)
- then handle every new connection in new thread:





I already did this much:














11 years ago

Lukasz Jarocki wrote:You need to use Threads and put every communication with client in another thread.


Can you please explain me more precise how to implement as im not clear.....
11 years ago
Im working on Server and Multiclient application.....when server prints any line on client;control is not coming back to server unless client enters any data so how to make control to come back to server so that it can print next statement for client.......
11 years ago
package com.simpragma.assignment.serverapplication;






I have written code for 1 client and server communication,its working fine.......For multi client i just used multithreading concept by extending Thread and overriding run but what next im not getting........
Ya message will be sent via server,server does work of message exchange between clients....
I'm working on Server and Multiclient application,im not able to send message from one specific client to another specific client.....How to identify message is from which client and how to send to particular client?.....
My Util class..

package com.simpragma.assignment.multithreading.messagehandler.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import org.apache.log4j.Logger;

import com.simpragma.assignment.multithreading.messagehandler.constants.MessageHandlerConstants;
import com.simpragma.assignment.multithreading.messagehandler.customexception.MessageHandlerException;

/**
* Name ConnectionUtil.java
*
* @author Amruta <br/>
* <b>Purpose </b> This class is designed based on Single ton design
* pattern.
*
******************************************************************************
* Audit Trails.</br> <br/>
* who when version comment</br>
* Amruta 20th December 2012 1.0 Base version created
******************************************************************************
*/

public class ConnectionUtil {
// A static logger variable so that it references the Logger instance named
// "EventManagerService.class"
private static Logger logger = Logger.getLogger(ConnectionUtil.class);

//Instance variables
static private ConnectionUtil connectionUtil=null;
private static Connection connection = null;
private static Properties properties=null;

//getter method for connection
public static Connection getConnection() {

return connection;
}


private ConnectionUtil() throws MessageHandlerException {
logger.debug("Entering constructor");
properties = new Properties();
properties.setProperty("driverClass", "com.mysql.jdbc.Driver");
properties.setProperty("uri", "jdbc:mysql://localhost:3306/SIMPRAGMA");
properties.setProperty("username", "root");
properties.setProperty("password", "123");

try {
properties.store(new FileOutputStream("/home/harshal/Amruta/" +
"Simpragma/Multithreading/MessageHandler/src/configfiles" +
"/config.properties"),null);
properties.load(new FileInputStream("/home/harshal/Amruta/Simpragma/"
+ "Multithreading/MessageHandler/src/configfiles/" +
"config.properties"));
// Loading driver class
Class.forName(properties.getProperty("driverClass"));
// Establishing connection

connection = DriverManager.getConnection(
properties.getProperty("uri"),
properties.getProperty("username"),
properties.getProperty("password"));

} catch (FileNotFoundException e) {
logger.error("Error Description",e);
MessageHandlerException exception = new MessageHandlerException();
exception.setErrorKey(MessageHandlerConstants.FILE_NOT_FOUND_KEY);
throw exception;
} catch (IOException e) {
logger.error("Error Description",e);
MessageHandlerException exception = new MessageHandlerException();
exception.setErrorKey(MessageHandlerConstants.IO_FAILURE_KEY);
throw exception;
} catch (ClassNotFoundException e) {
logger.error("Error Description",e);
MessageHandlerException exception = new MessageHandlerException();
exception.setErrorKey(MessageHandlerConstants.CLASS_NOT_FOUND_KEY);
throw exception;
} catch (SQLException e) {
logger.error("Error Description",e);
MessageHandlerException exception = new MessageHandlerException();
exception.setErrorKey(MessageHandlerConstants.SQL_ERROR_KEY);
throw exception;
}
logger.debug("Exiting constructor");
}

/**
* Instantiates ConnectionUtil class
*
* @return reference of ConnectionUtil class
* @throws MessageHandlerException
*/

public static ConnectionUtil getConnectionUtil() throws MessageHandlerException
{
logger.debug("Entering getConnectionUtil()");
if(connectionUtil==null)
{
connectionUtil=new ConnectionUtil();
}
logger.debug("Exiting getConnectionUtil()");
return connectionUtil;
}



/**
* Used to close object level resources.
*//*
@Override
protected void finalize() throws Throwable {
if(connection!=null)
{
connection.close();
}
}*/
}
I have come to know where is the problem but how to resolve i dnt know.........
Connection is an instance variable in my ConnectionUtil class and ConnectionUtil is SingleTon class and im initialising connection in constructor of ConnectionUtil....
In DAO layer once when i close connection in finally block of any method then it is closed permanently....As constructor of ConnectionUtil is executed only once..


So how to resolve this.
This is my code....Here ConnectionUtil is a Singleton class.

Connection is an instance variable in my class.Im initialising it in methods where im using it and closing it in a finally block of those methods.But i'm getting this below exception,though im initialising it in methods locally and closing it and declaration i ve done to class level.Reason for this?

Exception Description:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed
How to know whether a data base is updated with new row?Means my program is hitting DB every 1 minute but how to check whether new row is inserted or not?