kichu kichu

Ranch Hand
+ Follow
since May 10, 2001
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 kichu kichu

HI guys,
I'm trying to develop a tftp application in java.This is the specification i want:
Task is to implement a modified version of TFTP, as follows:
1- version will still run on top of UDP,
2- However, instead of having each packet be acknowledged before sending the next one, you will implement a TCP type of functionality: packets can be sent without waiting for an acknowledgement. The receiver has to keep track of sequence numbers and implement some type of ordering to �restore� the original format of the file. The sender should be informed of missing packets through duplicate ACKs, as we saw in class.
3- You only have to implement the binary type of data transmission.
4- Your TFTP server should be multi-threaded, i.e., it should support multiple client requests. This is done by creating a new thread for each client request that is received.
5- Your application should survive short outages. Transferring a large file and
disconnecting your Internet connection for a short time can test this. Upon reconnection, your client and the server should be able to pick up where they left off.
I have created four files:
1)tftpClient:The client
2)tftpServer:the server
3)tftpTransfer:It performs packet transfer and stuff
4)UdpData erforms udp packet functionality

tftpClient:
import java.net.*;
import java.io.*;
import java.util.*;
public class tftpClient {
public static void main(String argv[]) {
String host= argv[0],fileName=argv[1],line;
int replyLen,blockNum;
try {
// Process command line args.....
InetAddress server = InetAddress.getByName(host);
// DatagramSocket sock = new DatagramSocket(2000,InetAddress.getLocalHost());
DatagramSocket sock = new DatagramSocket();
FileOutputStream outFile = new FileOutputStream(fileName);
// Create the request packet and send it off
UdpData reqData = new UdpData(4+fileName.length()+5); // 5==len("octet")
reqData.putInt(2,0); // RREQ opcode
reqData.putString(fileName,2); // Requested file
reqData.putString("octet",2+fileName.length()+1); // Trans mode
DatagramPacket pack = reqData.mkPacket(server,2000); // 69==TFTP port
sock.send(pack);
System.out.println("host:"+server.toString());
System.out.println("sent on socket:"+sock);
// Create the ACK packet
UdpData ackData = new UdpData(4);
ackData.putInt(4,0); // ACK opcode
DatagramPacket ackPack = ackData.mkPacket(server,2000);
// Create a packet to receive the data
UdpData recData = new UdpData(516); // 516==max pak len
pack = recData.mkPacket();
System.out.println("receiving packet");
for(int pakLen=516; pakLen==516; ) {
sock.receive(pack);
pakLen=pack.getLength();
System.out.println("still...."+sock.toString());
if (recData.getInt(0)==3) { // If a DATA pak then...
blockNum=recData.getInt(2);
outFile.write(recData.getData(),4,pakLen-4);
ackData.putInt(blockNum,2);
ackPack = ackData.mkPacket(server,pack.getPort());
sock.send(ackPack);
}
else
throw new Exception();
};
outFile.close();
sock.close();
}
catch (Exception e) { System.out.println("tftp session failed"); }
}
}
2)tftpServer:
import java.net.*;
import java.io.*;
import java.util.*;
public class tftpServer {
// Tftp opcodes (RFC 1350)
public static final int tftpRRQ=1;
public static final int tftpWRQ=2;
public static final int tftpDATA=3;
public static final int tftpACK=4;
public static final int tftpERROR=5;
public static final int maxTftpPakLen=516;
public static void main(String argv[]) {
try {
DatagramSocket sock = new DatagramSocket(2000);
System.out.println("Server Ready. Listening on port: "+sock.getLocalPort());
for(; {
UdpData reqData = new UdpData(maxTftpPakLen);
DatagramPacket reqPak = reqData.mkPacket();
System.out.println("ready to receive request");
sock.receive(reqPak);
System.out.println("received request at socket:"+sock.toString());
if (reqData.getInt(0)==tftpRRQ) {
System.out.println("Display this:");
System.out.println("Request from "+reqPak.getAddress());
tftpTransfer t = new tftpTransfer(reqPak);
}
}
}
catch(Exception e) { System.out.println("Server terminated"); }
}
}
3)tftpTransfer:
import java.net.*;
import java.io.*;
import java.util.*;
class tftpTransfer extends Thread {
protected DatagramSocket sock;
protected InetAddress clientIP;
protected int clientPort;
protected FileInputStream source;
protected UdpData dataPak;
public tftpTransfer(DatagramPacket reqPak) {
try {
sock = new DatagramSocket();
clientIP = reqPak.getAddress();
clientPort = reqPak.getPort();
UdpData reqData = new UdpData(reqPak);
File srcFile = new File(reqData.getString(2));
if (srcFile.exists() && srcFile.isFile() && srcFile.canRead()) {
source = new FileInputStream(srcFile);
dataPak = new UdpData(516); // 516==max pak len
dataPak.putInt(3,0); // 3==DATA opcode
this.start();
}
} catch (Exception e) { System.out.println("Client failed"); };
}
public void run() {
int bytesRead = 512;
DatagramPacket ack = new DatagramPacket(new byte[4],4);
try {
for (int blkNum=0; bytesRead==512; blkNum++) { // 512==max data len
dataPak.putInt(blkNum,2);
bytesRead = source.read(dataPak.getData(),4,512);
sock.send(dataPak.mkPacket(clientIP,clientPort,516)); // 516==max data len + header
sock.receive(ack);
}
} catch (Exception e) { System.out.println("Client failed"); }
try {
source.close();
sock.close();
} catch (Exception e) {};
}
}
4)UdpData.java:
import java.net.*;
import java.io.*;
import java.util.*;
public class UdpData {
private byte data[];
public UdpData(int len) { data = new byte[len]; };
public UdpData(DatagramPacket pack) { data = pack.getData(); }
public byte[] getData() { return data; };
public int length() { return data.length; };
public DatagramPacket mkPacket() { return new DatagramPacket(data,data.length); };
public DatagramPacket mkPacket(int len) { return new DatagramPacket(data,len); };
public DatagramPacket mkPacket(InetAddress dest, int port) {
return new DatagramPacket(data,data.length,dest,port);
};
public DatagramPacket mkPacket(InetAddress dest, int port, int len) {
return new DatagramPacket(data,len,dest,port);
};
public int getInt(int offset) {
// Fix to avoid sign extension
// Remember what the MSB is and then turn it off to avoid sign extension. It is
// then added back to the sum after everything has been converted to integers.
byte lo = data[offset+1];
int signBit = (int)(lo&0x80);
lo&=0x7f;
// Standard TCP/IP byte order is hiByte followed by loByte (big endian)
int hiByte = (int)data[offset];
int loByte = (int)lo;
return (hiByte<<8)+signBit+loByte;
};
public void putInt(int val, int offset) {
int loByte = val%256;
int hiByte = val>>>8;
// Standard TCP/IP byte order is hiByte followed by loByte (big endian)
data[offset] = (byte)hiByte;
data[offset+1] = (byte)loByte;
};
public String getString(int offset) {
StringBuffer strBuf = new StringBuffer();
int curPos = offset;
while (data[curPos]!=0) {
strBuf.append((char)data[curPos]);
curPos++;
}
return new String(strBuf);
};
public void putString(String str, int offset) {
str.getBytes(0,str.length(),data,offset);
data[offset+str.length()]=0;
};
}
BUT I STILL CAN'T GET IT TO WORK.THE CLIENT IS SENDING A REQUEST FOR A FILE FROM THE SERVER AND IT JUST HANGS.THE SERVER IS UP AND WAITING FOR REQUESTS.

CAN ANYONE HELP ME WITH THIS???
THANKS A LOT,
KICHU
HI guys,
I'm trying to develop a tftp application in java.This is the specification i want:
Task is to implement a modified version of TFTP, as follows:
1- version will still run on top of UDP,
2-However, instead of having each packet be acknowledged before sending the next one, you will implement a TCP type of functionality: packets can be sent without waiting for an acknowledgement. The receiver has to keep track of sequence numbers and implement some type of ordering to �restore� the original format of the file. The sender should be informed of missing packets through duplicate ACKs, as we saw in class.
3-You only have to implement the binary type of data transmission.
4-Your TFTP server should be multi-threaded, i.e., it should support multiple client requests. This is done by creating a new thread for each client request that is received.
5-Your application should survive short outages. Transferring a large file and
disconnecting your Internet connection for a short time can test this. Upon reconnection, your client and the server should be able to pick up where they left off.
I have created four files:
1)tftpClient:The client
2)tftpServer:the server
3)tftpTransfer:It performs packet transfer and stuff
4)UdpData erforms udp packet functionality

tftpClient:
import java.net.*;
import java.io.*;
import java.util.*;
public class tftpClient {
public static void main(String argv[]) {
String host= argv[0],fileName=argv[1],line;
int replyLen,blockNum;
try {
// Process command line args.....
InetAddress server = InetAddress.getByName(host);
// DatagramSocket sock = new DatagramSocket(2000,InetAddress.getLocalHost());
DatagramSocket sock = new DatagramSocket();
FileOutputStream outFile = new FileOutputStream(fileName);
// Create the request packet and send it off
UdpData reqData = new UdpData(4+fileName.length()+5); // 5==len("octet")
reqData.putInt(2,0); // RREQ opcode
reqData.putString(fileName,2); // Requested file
reqData.putString("octet",2+fileName.length()+1); // Trans mode
DatagramPacket pack = reqData.mkPacket(server,2000); // 69==TFTP port
sock.send(pack);
System.out.println("host:"+server.toString());
System.out.println("sent on socket:"+sock);
// Create the ACK packet
UdpData ackData = new UdpData(4);
ackData.putInt(4,0); // ACK opcode
DatagramPacket ackPack = ackData.mkPacket(server,2000);
// Create a packet to receive the data
UdpData recData = new UdpData(516); // 516==max pak len
pack = recData.mkPacket();
System.out.println("receiving packet");
for(int pakLen=516; pakLen==516; ) {
sock.receive(pack);
pakLen=pack.getLength();
System.out.println("still...."+sock.toString());
if (recData.getInt(0)==3) { // If a DATA pak then...
blockNum=recData.getInt(2);
outFile.write(recData.getData(),4,pakLen-4);
ackData.putInt(blockNum,2);
ackPack = ackData.mkPacket(server,pack.getPort());
sock.send(ackPack);
}
else
throw new Exception();
};
outFile.close();
sock.close();
}
catch (Exception e) { System.out.println("tftp session failed"); }
}
}
2)tftpServer:
import java.net.*;
import java.io.*;
import java.util.*;
public class tftpServer {
// Tftp opcodes (RFC 1350)
public static final int tftpRRQ=1;
public static final int tftpWRQ=2;
public static final int tftpDATA=3;
public static final int tftpACK=4;
public static final int tftpERROR=5;
public static final int maxTftpPakLen=516;
public static void main(String argv[]) {
try {
DatagramSocket sock = new DatagramSocket(2000);
System.out.println("Server Ready. Listening on port: "+sock.getLocalPort());
for(; {
UdpData reqData = new UdpData(maxTftpPakLen);
DatagramPacket reqPak = reqData.mkPacket();
System.out.println("ready to receive request");
sock.receive(reqPak);
System.out.println("received request at socket:"+sock.toString());
if (reqData.getInt(0)==tftpRRQ) {
System.out.println("Display this:");
System.out.println("Request from "+reqPak.getAddress());
tftpTransfer t = new tftpTransfer(reqPak);
}
}
}
catch(Exception e) { System.out.println("Server terminated"); }
}
}
3)tftpTransfer:
import java.net.*;
import java.io.*;
import java.util.*;
class tftpTransfer extends Thread {
protected DatagramSocket sock;
protected InetAddress clientIP;
protected int clientPort;
protected FileInputStream source;
protected UdpData dataPak;
public tftpTransfer(DatagramPacket reqPak) {
try {
sock = new DatagramSocket();
clientIP = reqPak.getAddress();
clientPort = reqPak.getPort();
UdpData reqData = new UdpData(reqPak);
File srcFile = new File(reqData.getString(2));
if (srcFile.exists() && srcFile.isFile() && srcFile.canRead()) {
source = new FileInputStream(srcFile);
dataPak = new UdpData(516); // 516==max pak len
dataPak.putInt(3,0); // 3==DATA opcode
this.start();
}
} catch (Exception e) { System.out.println("Client failed"); };
}
public void run() {
int bytesRead = 512;
DatagramPacket ack = new DatagramPacket(new byte[4],4);
try {
for (int blkNum=0; bytesRead==512; blkNum++) { // 512==max data len
dataPak.putInt(blkNum,2);
bytesRead = source.read(dataPak.getData(),4,512);
sock.send(dataPak.mkPacket(clientIP,clientPort,516)); // 516==max data len + header
sock.receive(ack);
}
} catch (Exception e) { System.out.println("Client failed"); }
try {
source.close();
sock.close();
} catch (Exception e) {};
}
}
4)UdpData.java:
import java.net.*;
import java.io.*;
import java.util.*;
public class UdpData {
private byte data[];
public UdpData(int len) { data = new byte[len]; };
public UdpData(DatagramPacket pack) { data = pack.getData(); }
public byte[] getData() { return data; };
public int length() { return data.length; };
public DatagramPacket mkPacket() { return new DatagramPacket(data,data.length); };
public DatagramPacket mkPacket(int len) { return new DatagramPacket(data,len); };
public DatagramPacket mkPacket(InetAddress dest, int port) {
return new DatagramPacket(data,data.length,dest,port);
};
public DatagramPacket mkPacket(InetAddress dest, int port, int len) {
return new DatagramPacket(data,len,dest,port);
};
public int getInt(int offset) {
// Fix to avoid sign extension
// Remember what the MSB is and then turn it off to avoid sign extension. It is
// then added back to the sum after everything has been converted to integers.
byte lo = data[offset+1];
int signBit = (int)(lo&0x80);
lo&=0x7f;
// Standard TCP/IP byte order is hiByte followed by loByte (big endian)
int hiByte = (int)data[offset];
int loByte = (int)lo;
return (hiByte<<8)+signBit+loByte;
};
public void putInt(int val, int offset) {
int loByte = val%256;
int hiByte = val>>>8;
// Standard TCP/IP byte order is hiByte followed by loByte (big endian)
data[offset] = (byte)hiByte;
data[offset+1] = (byte)loByte;
};
public String getString(int offset) {
StringBuffer strBuf = new StringBuffer();
int curPos = offset;
while (data[curPos]!=0) {
strBuf.append((char)data[curPos]);
curPos++;
}
return new String(strBuf);
};
public void putString(String str, int offset) {
str.getBytes(0,str.length(),data,offset);
data[offset+str.length()]=0;
};
}
BUT I STILL CAN'T GET IT TO WORK.THE CLIENT IS SENDING A REQUEST FOR A FILE FROM THE SERVER AND IT JUST HANGS.THE SERVER IS UP AND WAITING FOR REQUESTS.

CAN ANYONE HELP ME WITH THIS???
THANKS A LOT,
KICHU
17 years ago
Hi sachin,
Create a folder inside classes\sunexamples.
eg classes\sunexamples\sachin.
save your java file inside this folder.
See that in the java file you save here,you should specify the package as
package foldername(sachin in this case).
hope that helps,
kichu
19 years ago
Hi,
Which webserver are you using sachin?
regards,
kichu
19 years ago
Hi,
I have been using tomcat 3.2.1 now for a long time.I tried the new beta version for some time,but i found out that the older version was more stable.
I think you should not do any development work using a beta version as it is bound to have a number of bugs.
Install an older version from==>
http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.2.3/bin/
regards,
kichu(the choice is yours!)
19 years ago
Hi tom,
The old pages are stored in "tomcat\work" folder.Delete the contents of this folder and try again.
alternatively you may also clear your browser cache and history.
regards,
kichu
19 years ago
Hi geetha,
You have stored your jsp file at this location=>
C:\programfiles\allaire\jrun\servers\default\default-app\web-inf\jsp
BY default the jsp files are stored at ==>
C:\programfiles\allaire\jrun\servers\default\default-app\.
As you know there are two servers ,the admin and the default.
We use the default server whose port number is 8100.
The port number of the admin server is 8000.
You have typed 8000 instead of typing 8100.
SO your correct path should be==> http://localhost:8100/name of your file.
This is if you are saving your file inside default-app as i mentioned above.
If u want to save it in another location u will have to set that path in the classpath settings.
I hope u have understood what i explained.
If u are still having problems ,post your problem or mail me at
kichuhere@rediffmail.com
regards,
kichu
[This message has been edited by kichu kichu (edited August 21, 2001).]
[This message has been edited by kichu kichu (edited August 21, 2001).]
19 years ago
Hi amit,
Every server in JRun has its own java virtual machine. You
change the classpath for that particular server so it loads first the
classes in a local directory of that server, and then the classes in
"\JRun\lib\ext". That way you don't have to put anything in the
"JRun\lib\ext" folder and the JRun application and the other servers (Admin,
Default) are not affected by your experiments.
Step 1: restore JRun to the original configuration or reinstall JRun so it
works again.
Step 2: create a new server (e.g. "Fopserver" ) (see setup guide). Now you
have 3 servers in "C:\Program Files\Allaire\JRun\servers" : "admin",
"default" and "Fopserver" .
This step is not really necessary, you can also use the existing default
server if you want. In that case replace in the following steps "Fopserver"
with "default".
Step 3: edit the file
"C:\Program Files\Allaire\JRun\servers\Fopserver\local.properties" :
Change (or add if it doesn't exist) the line that starts with
"java.classpath=" to:
java.classpath={user.classpath};{jrun.classpath};{ejb.classpath};{servlet.cl
asspath}
For a definition of all these {...} see "C:\Program
Files\Allaire\JRun\lib\global.properties".
Items in local.properties of a server override for that server the ones in
global.properties.
Step 4: put all the apache jars(Xerces,Xalan,Fop,...) and other jars you
need in the folder "C:\Program Files\Allaire\JRun\servers\Fopserver\lib".
They will be available to all apps in that server.
Try these steps and get back to me.
regards,
kichu
19 years ago
Hai,
I too have this problem.I have installed jrun3.0.But this does not prevent me from running my programs using jrun.
They are running pretty smoothly.
What i'm doing is ,at the browser type==>http://localhost:8000
This inturn opens up a loginpage.Type in your username and password here.Now you will come to the index page.
Here you can control both the admin and default servers.(ie.u can start and stop them)..
As this procedure is working fine for me,i'm going along with it.
try it out and send a reply.
regards,
kichu
19 years ago
Hai,
Usually the tomcat.conf file is present inside the conf folder.
I'm using tomcat 3.2.1 and it contains the tomcat.conf file.
I guess the tomcat version you rae using is a beta version.
Try installing version 3.2.1
Tomcat is a separate webserver and it is more than sufficient to run your jsp,servlets etc.You do not require apache for it.Tomcat alone will do the work.
regards,
kichu
19 years ago
Hai,
I'm using an applet and making modifications to it.By just refreshing,the changes are not getting displayed on the browser.
I'm having to restart the server.Let me add that i'm using IE6.0(since it is a beta version maybe that is the problem).
what do you think??Any solutions???
regards,
kichu
19 years ago
Hai,
I'm running my jsps on jrun server.The problem that i'm facing is that everytime i make some modifications to my jsp pages ,i'm having to restart my server in order to reflect those changes on my browser.
Does anyone know what could be the problem?
any help is appreciated.
regards,
kichu
19 years ago
WOW,
That question answer session got over pretty quickly!!!


kichu
19 years ago
Hai,
This is a reply that i had sent to another javaranch user who was facing problems with tomcat installation.
Please check out whether these are the steps you followed while installation.(The steps are below)
At the browser,if u type==>http://localhost:8080
u will get homepage if your installation has been proper.
This is the url of the site from which u can download tomcat.Download jakarta-tomcat-3.2.1.zip for win machines. http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.2.1/bin/
The steps are
1)After you download tomcat from the net,U will get a zip file.
2)Extract that zip file to your drive eg D drive.U just need to right click the zip file and select the drive to extract it to.
3)Automatically a folder called jakarta-tomcat will be created in that specific drive.
4)Rename the folder to tomcat.
5)There will be a folder called webapps inside tomcat containing 4 war files.
6)Go to environment variables in NT and 2000.set path as==>
TOMCAT_HOME with value Drivename:\tomcat
7)similarily set JAVA_HOME with value Drivename:\jdkx.x
here x.x being the version.
IF it is a 95 system set the above paths in autoexec.bat.
Now go to bin and run startup.
U will hopefully see a window popping up from which a new one will pop up.
Now u are up and running

send a reply if you face any difficulty
regards,
kichu
19 years ago
Hai,
See in the folder tomcat\webapps\ROOT.Look if index.html file is there.This is the page which gets displayed when we type==>hhtp://localhost:8080.
If this page is not there ,then you will get page not found.
Additionaly put a simple html page inside webapps\ROOT ,for example 1.html.
Then access it by typing==>http://localhost:8080/1.html
See if it is getting displayed.If yes,your tomcat is running properly.
try it and reply to me
kichu
19 years ago