harry ganguly

Greenhorn
+ Follow
since Dec 14, 2010
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 harry ganguly

Server opens a port in server machine... and client send a command to server to execute...
example: cmd /c notepad.exe.
This will open notepad in server.

The server code is working fine and is opening a port as required. But when same client code is throwing "java.net.SocketException: Connection reset" exception when I run. Please note:
Client machine frm which Im running the client code is the same. But the server machine changes. In one server machine, it's working fine, but in another server machine it's not... what might be the issue here???
could someone please suggest.
Ive requirement to send some command line argument to server. So Ive written server code which opens a port in server:
Server:
public class FTPServer {

private ServerSocket serverSocket;
FTPServer(int port) {

try
{
serverSocket = new ServerSocket(port);
System.out.println("Server waiting for client on port " + serverSocket.getLocalPort());
int i=0;

while(true)
{
i=i+1;
Socket socket = serverSocket.accept(); // accept connection
System.out.println("New client asked for a connection");

TcpThread t = new TcpThread(socket,i); // make a thread of it
System.out.println("Starting a thread for a new Client");
t.start();
}
}
catch (IOException e) {
System.out.println("Exception on new ServerSocket: " + e);
}
}

public static void main(String[] args) {
int port=0;
for (String s: args)
{
port=Integer.parseInt(args[0]);
}
System.out.println("Port: "+port);
new FTPServer(port);
}

/** One instance of this thread will run for each client */
class TcpThread extends Thread {
Socket socket;
ObjectInputStream Sinput;
ObjectOutputStream Soutput;
String command=null;
int j=0;

TcpThread(Socket socket,int i) {
this.socket = socket;
j=i;
}
public void run() {
/* Creating both Data Stream */
System.out.println("Thread trying to create Object Input/Output Streams");
try
{
Soutput = new ObjectOutputStream(socket.getOutputStream());
Soutput.reset();
Sinput = new ObjectInputStream(socket.getInputStream());
}
catch (IOException e) {
System.out.println("Exception creating new Input/output Streams: " + e);
return;
}
System.out.println("Thread waiting for a String from the Client");
try {
String str = (String) Sinput.readObject();

Runtime.getRuntime().exec(str);
command="Server replying back for the "+j+"th time";
Soutput.writeObject(command);
Soutput.flush();
}
catch (IOException e) {
System.out.println("Exception reading/writing Streams: " + e);
return;
}
catch (ClassNotFoundException o) {
}
finally {
try {
Soutput.close();
Sinput.close();
}
catch (Exception e) {
}
}
}
}
}
Client:
ObjectOutputStream Soutput; // towrite on the socket
ObjectInputStream Sinput; // to read the socket
Socket socket;

try {
socket = new Socket(ip, port);
} catch (Exception e) {
fail("Error connectiong to server:" + e);
return;
}
System.out.println("Connection accepted " + socket.getInetAddress() + ":" + socket.getPort() + "\n");
/* Creating both Data Streams */
try {
Soutput = new ObjectOutputStream(socket.getOutputStream());
Soutput.reset();
System.out.println(socket.getInputStream());
Sinput = new ObjectInputStream(socket.getInputStream());
} catch (IOException e) {
e.printStackTrace();
return;
}
// send the command (String) to the server
info("Client sending \"" + command + "\" to server\n");
try {
Soutput.writeObject(command);
Soutput.flush();
} catch (IOException e) {
e.printStackTrace();
return;
}
// read back the answer from the server
String response;
try {
response = (String) Sinput.readObject();
System.out.println("Read back from server: " + response);
} catch (Exception e) {
e.printStackTrace();
}
try {
Sinput.close();
Soutput.close();
} catch (Exception e) {
}
I'm writing one client server program.
Client snippet goes like this:


Server Snippet goes like this:

when running this locally in localhost it's working properly where as in remote server, it;s throwing following error:
java.io.StreamCorruptedException: invalid stream header: 4348414C

Please help...
11 years ago

harry ganguly wrote:Hi chaitanya,
Can you please give me one example??Since i cant find cell.setCellValue(val) function if i use jxl.jar. How to set val in a cell???

It'd be really helpful if you can put some light on the same.



I'm asking in reference to jxl.jar. Please give an example..
12 years ago
Hi chaitanya,
Can you please give me one example??Since i cant find cell.setCellValue(val) function if i use jxl.jar. How to set val in a cell???

It'd be really helpful if you can put some light on the same.
12 years ago
@Jan: FileOuputStream will create a new wb....which is not my reqmnt.

12 years ago
@Wim: I could not find the perticular value in cell(1:6) after fis.close(). Your understanding is right.
@Ulf: Whatever it may be, I want to have cell(1,6) value="x" without hampering other cells values.

Is there anyway I can do it?Can anyone tell me some way to do so??
12 years ago
Thanks Joshua for pointing out the general way of pointing a sheetname.

Though this does not serve my requirement. If I go with your way, then the original file will be updated rather than getting updated. I just want to add one cell value rather than rewriting the file. So this is like append rather than overwrite

Could someone please give me some idea on this???
12 years ago
This'll create a new cell and also will overwrite the existing file. Where as I want to only update my existing file inserting some value(String val in code) in perticular cell,row.

12 years ago
Hi All,
I want to write in an existing excel(in sheet1) file in a perticular cell(say row=1,cell=6). I'm using poi jar. But I could not write in that perticular cell.
String val= //value that I want to write;

String filePath = //getting the filepath. ;
File file=new File(filePath);
FileInputStream fis=new FileInputStream(file);


HSSFWorkbook wb=new HSSFWorkbook(fis);
HSSFSheet st=wb.getSheet("Sheet1");
HSSFRow row=st.getRow(1);
HSSFCell cell= row.getCell(6);
cell.setCellValue(val);
fis.close();


This should write val to sheet1, row 1 cell 6 of the perticular excel that I'm passing. In filepath I'm passing file path along with file name.

But this is not working though not throwing any errors.
Could someone please help?
12 years ago
Hi All,
I want to write in an existing excel(in sheet1) file in a perticular cell(say row=1,cell=6). I'm using poi jar. But I could not write in that perticular cell.
String val= //value that I want to write;

String filePath = //getting the filepath. ;
File file=new File(filePath);
FileInputStream fis=new FileInputStream(file);


HSSFWorkbook wb=new HSSFWorkbook(fis);
HSSFSheet st=wb.getSheet("Sheet1");
HSSFRow row=st.getRow(1);
HSSFCell cell= row.getCell(6);
cell.setCellValue(val);
fis.close();


This should write val to sheet1, row 1 cell 6 of the perticular excel that I'm passing. In filepath I'm passing file path along with file name.

But this is not working though not throwing any errors.
Could someone please help?
12 years ago
Hi,
I've to export resultset or collection which is taken from DB to sas file. extention is *.sas7bdat. Can you please help me out.

I can export to xml or excel file. If i can convert excel or xml to sas file then also my requirement is fulfilled to some extent.

Can anyone give me the solution of anyone of the above in java??
13 years ago