I was trying code from this link to send file using UDP,
Emulate UDP Over TCP in multithread Server & Client
But i'm getting EOF exception, I don't know why this code is giving such error, i doubled check the code , it seems right, I will be grateful for any help, i need this code for my thesis. Thanks in advance !!!!
SERVER: Accepted connection.
SERVER: receivedput C:\Users\Nika\workspace\test\10MB.txt
THREAD: put C:\Users\Nika\workspace\test\10MB.txt
*** Ready to receive file on port: 60829 ***
*** The file will be saved as: Recieved-10MB.txt ***
*** Expecting to receive: 104857600 bytes ***
Mar 30, 2014 11:17:39 PM udpemu.CLIENTConnection run
SEVERE: null
java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at udpemu.UDPFileReceiver.deserialize(UDPFileReceiver.java:126)
at udpemu.UDPFileReceiver.<init>(UDPFileReceiver.java:52)
at udpemu.CLIENTConnection.run(CLIENTConnection.java:60)
at java.lang.Thread.run(Unknown Source)
Related
My application makes call to Cipher.getInstance so it can decrypt passwords.
In certain environments this is creating a problem because the Cipher.getInstance method ends up trying to make an FTP call which is hanging.
Does anyone know how to avoid this FTP call or prevent it hanging?
Here is the stacktrace.
java.net.PlainSocketImpl.socketConnect(Native Method)
java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:370)
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:231)
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:213)
java.net.Socket.connect(Socket.java:643)
java.net.Socket.connect(Socket.java:590)
sun.net.ftp.impl.FtpClient.doConnect(FtpClient.java:971)
sun.net.ftp.impl.FtpClient.tryConnect(FtpClient.java:931)
sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1026)
sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1012)
sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:307)
sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:406)
sun.net.www.protocol.jar.URLJarFile.retrieve(URLJarFile.java:227)
sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:84)
sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:128)
sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:136)
sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:103)
javax.crypto.a$0.run(Unknown Source)
java.security.AccessController.doPrivileged(AccessController.java:420)
javax.crypto.a.a(Unknown Source)
javax.crypto.a.a(Unknown Source)
javax.crypto.a.a(Unknown Source)
javax.crypto.b.a(Unknown Source)
javax.crypto.d.a(Unknown Source)
javax.crypto.d.a(Unknown Source)
javax.crypto.Cipher.c(Unknown Source)
javax.crypto.Cipher.b(Unknown Source)
javax.crypto.Cipher.getInstance(Unknown Source)
javax.crypto.Cipher.getInstance(Unknown Source)
I consistently encounter java httpurlconnections, which, even with a setReadTimeOut(), will not throw a sockettimeoutexception when they should, and it is consistently associated with an eventual (after hanging for 2-3 minutes) Premature EOF Exception. I read in a few blogs that this may have to do with reading in using BufferedReader's readLine method,
String x = ""; while((x=bufferedReader.readLine())!=null){}
at the end of a file if there is no new line character at the end of an inputstream. This does not make sense, why doesn't java's setTimeOut function correctly?
URL url=new URL("");
c=(HttpURLConnection)url.openConnection();
c.setReadTimeout(17000);
BufferedReader b = new BufferedReader(new InputStreamReader(c.getInputStream()));
String s;
while((s=b.readLine())!=null)
{
} ect.
java.io.IOException: Premature EOF
at sun.net.www.http.ChunkedInputStream.readAheadBlocking(Unknown Source)
at sun.net.www.http.ChunkedInputStream.readAhead(Unknown Source)
at sun.net.www.http.ChunkedInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
Here are the Response Headers (with exact cookie info truncated):
[HTTP/1.1 200 OK]
p3p ["",""]
x-frame-options [SAMEORIGIN]
Date [Tue, 08 May 2012 15:01:40 GMT]
Vary [Accept-Encoding,User-Agent]
Transfer-Encoding [chunked]
Set-cookie [""=""; path=/; domain=""; expires=Tue, 01-Jan-2036 08:00:01 GMT]
Content-Type [text/html; charset=ISO-8859-1]
Server [Server]
See the documentation for setReadTimeout:
Some non-standard implementation of this method ignores the specified timeout.
If you don't think that's the issue, set the timeout to a very low number like 1 and check. You should get a java.net.SocketTimeoutException exception.
I need an example to convert Spanish language to English language using Google Translation API. I tried with the following code. It gives some exception. can someone help me on the same.
Code :
import com.google.api.translate.*;
public class GoogleTranslator {
/**
* #param args
*/
#SuppressWarnings("deprecation")
public static void main(String[] args) {// TODO code application logic here
try {
Translate.setHttpReferrer("sp-en");
String translatedText = Translate.translate("Hola mundo", Language.SPANISH, Language.ENGLISH);
System.out.println(translatedText);
} catch (Exception ex) {
ex.printStackTrace(); }
}
}
Error :
java.lang.Exception: [google-api-translate-java] Error retrieving translation.
at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:136)
at com.google.api.translate.Translate.execute(Translate.java:69)
at com.google.api.translate.Translate.translate(Translate.java:192)
at GoogleTranslator.main(GoogleTranslator.java:15)
Caused by: java.net.UnknownHostException: ajax.googleapis.com
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:115)
... 3 more
You need to figure out why you don't reach this host: ajax.googleapis.com
The Exception says:
java.net.UnknownHostException: ajax.googleapis.com
The javadoc says UnknownHostException is thrown to indicate that the IP address of a host could not be determined.
You should your DNS.
nslookup ajax.googleapis.com
Set your DNS to google one
if on linux machine
sudo gedit /etc/resolv.conf
add
nameserver 8.8.8.8
nameserver 8.8.4.4
or if on windows goto network setting and set DNS for active connection
you don't have an api key, for example GoogleAPI.setKey(); you need something like this to continue i guess
I'm having the code below..
System.setProperty("http.proxyHost","176.6.129.25") ;
System.setProperty("http.proxyPort", "8080") ;
Authenticator.setDefault(new MyAuthenticator());
//http://deadlock.netbeans.org/hudson/api/xml
*URL url = new URL("http://in8301782d:8080/api/xml");*
Document dom = new SAXReader().read(url);
for( Element job : (List<Element>)dom.getRootElement().elements("job")) {
System.out.println(String.format("Name:%s\tStatus:%s",
job.elementText("name"), job.elementText("color")));
}
This code is working if I replace with http://deadlock.netbeans.org/hudson/api/xml , but it is not working with http://in8301782d:8080/api/xml. Infact If I type the samething in browser it is working.. If I replace the hostname with Ip address also not working.
The exception I'm getting is below.
*With in8301782d (machine name)* :
xception in thread "main" org.dom4j.DocumentException: http://in8301782d:8080/api/xml Nested exception: http://in8301782d:8080/api/xml
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
Nested exception:
java.io.FileNotFoundException: http://in8301782d:8080/api/xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1243)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
*With Ip (http://176.6.55.55:8080/api/xml):*
Exception in thread "main" org.dom4j.DocumentException: Server returned HTTP response code: 503 for URL: http://176.6.66.156:8080/api/xml Nested exception: Server returned HTTP response code: 503 for URL: http://176.6.66.156:8080/api/xml
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
Nested exception:
java.io.IOException: Server returned HTTP response code: 503 for URL: http://176.6.66.156:8080/api/xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
This doesn't appear to be a problem with your code.
In the first exception, SAX is telling you that it cannot find http://in8301782d:8080/api/xml - it cannot reach this URL. If the URL works in your browser, then perhaps the proxy setup is at fault.
In the second exception, SAX is reporting that the server is returning a non-success HTTP status code of 503, which (according to the HTTP specification) means:
The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay.
Of course, the application sitting at this URL may be sending you a HTTP 503 for some non-standard reason as well.
Loading classifier from D:\PROJECT\classifiers\NERDemo\classifiers\ner-eng-ie.crf-3-all2008.ser.gz ... done [2.0 sec].
Original Query was riot in India.
Parsing Queries and expanding tokens from the Ontologies..
{locations=[India], events=[riot]}
Search query is null
Something went wrong...
java.net.UnknownHostException: ajax.googleapis.com
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 sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.girs2.SearchHandler.makeQuery(SearchHandler.java:35)
at org.girs2.GIRS.search(GIRS.java:37)
at org.girs2.GIRS.main(GIRS.java:62)
Exception in thread "main" java.lang.NullPointerException
at org.girs2.GIRS.search(GIRS.java:44)
at org.girs2.GIRS.main(GIRS.java:62)
Looks like you probably have or had a DNS lookup failure. This tells you what happened:
java.net.UnknownHostException: ajax.googleapis.com
If you always get this exception and you can otherwise access this host by name, then I don't know what this could be, but odds are that this was a temporary DNS failure.
What should you do when you get this Exception? Well, if the address is one that you fully expect you should be able to get to -- such as this one -- then when you catch the Exception, you sleep for a while (perhaps 10 or 15 seconds, maybe even 30 or 60 seconds, depending on your application's needs) and try again.
If after several retries -- don't just retry forever! -- you still cannot reach the site, then log a reasonable complaint or otherwise complain that you cannot reach the site and have your application exit.
There's not much you can do when DNS fails except give up or wait and try again.