Johhn Davis

Greenhorn
+ Follow
since Sep 20, 2012
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
7
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Johhn Davis


Here i am getting my computer name and my computer ip as an output. Now suppose i have an another lappy connected with my lappy through modem and i am intending to get its computer name and its IP address ( which i manually assigned it as 192.168.1.3 ) . What changes i am supposed to do ?


No error that's good, & No response


I got that.

Jeff thanks for helping me here & in other threads too. Well i still couldn't get how to use that GET/ ,beside i give my best to play with sockets

Sharing a Joke :
" When Your life is in Darkness, pray GOD and ask him to free you from Darkness, Even after you pray, if You are still in Darkness please PAY ELECTRICITY BILL "

Output of this Code :

JOHN-PC/192.168.1.2
google.com/74.125.236.1


Now I want to pass IP address & get the Domain Name or URL ...... which code should i type ?


Try reading what gets sent as response and print it to the console to be sure.



I don't yet how to do this (may be i) . I assume it should be like , i am unicasting and it comes back (if so) , i store it in somewhere and watch the output at console.
But i did something. I switched off the Modem , run the code and Got the error.
Now i edited it as :


I didn't get any error . Ulf does it mean success ?
After editing

I am receiving different error :

Exception in thread "main" java.net.UnknownHostException: http://www.google.com
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at Demo.main(Demo.java:9)


Jeff & Pat, where i am supposed to write GET / HTTP/1.0 ? When I put this at google url i got same error UnknownHostException .
no particular reason, it was just hit & trial method to check such code.
well thanks for reply.



Facing many errors in Eclipse :

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at Demo.main(Demo.java:9)
It reveals we can't defined a method inside another method. Is it ?
thanks for reply.



Eclipse displays error -----> at thread.main(thread.java:11)
well thanks to Mr. Biswas, Mr. Docherty & Mr. Sokolovic

Mr. Sokolovic i followed your instruction , got success ( thumbs up). I placed the pqr.txt in root directory. After running the program it created the file xyz.txt with all contents copied.
Henceforth i will use code tags.

To find out which directory your system is using as root. Mr. Docherty & Mr. Sokolovic thumbs up for both
5 years ago
I using Eclipse (version : juno release) , win7 64bit , Java7

C:\Users\John\workspace\FirstGUI\bin\pqr.txt
C:\Users\john\workspace\FirstGUI\bin\demo.class

both files are in same directory
what's Root directory here ? or how to grant read access to that file ?

5 years ago

import java.io.*;
public class demo
{
public static void main(String args[])
{
try
{
FileReader fr = new FileReader("pqr.txt");
FileWriter fw = new FileWriter("xyz.txt");

int k;
while( ( k = fr.read() ) != -1 )
{
fw.write(k);
System.out.print((char) k);
}
fw.close();
fr.close();
}
catch(FileNotFoundException e)
{
System.out.println("File does not exist. " + e);
}
catch(IOException e)
{
System.out.println("Some I/O problem. " + e);
}
}
}


I am trying to copy contents of pqr.txt to xyz.txt. I have manually created a file pqr.txt in the same folder of class demo. I am getting the Error --- > File does not exist. java.io.FileNotFoundException: pqr.txt (The system cannot find the file specified)
5 years ago