When i'm trying to connect to tarantool server i get the following error:
Exception in thread "main" java.net.ConnectException: Connection
refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native
Method) at
java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at
java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at
java.net.Socket.connect(Socket.java:589) at
java.net.Socket.connect(Socket.java:538) at
java.net.Socket.(Socket.java:434) at
java.net.Socket.(Socket.java:211) at
TarantoolKt.main(Tarantool.kt:37)
My code:
class Tarantool {
val client: TarantoolClient
init {
val config: TarantoolClientConfig = TarantoolClientConfig()
config.apply {
username = "test"
password = "test"
}
val socketChannelProvider: SocketChannelProvider = SocketChannelProvider { _, p1 ->
when(p1) {
null -> {
println("Trying to connect . . .")
SocketChannel.open(InetSocketAddress("192.168.1.254", 3301)) // <- error
}
else -> {
p1.printStackTrace(System.out)
null!!
}
}
}
client = TarantoolClientImpl(socketChannelProvider, config)
}
}
fun main(args: Array<String>): Unit {
val client: Tarantool = Tarantool()
println(client.client.isAlive)
}
I get the same error when i'm trying to use different ip
It's the same as in tutorial here: https://github.com/tarantool/tarantool-java/
I'd also created the test user using this commands:
box.schema.user.create('test', { password = 'test' })
box.schema.user.grant('test', 'execute,read,write', 'universe')
I use docker for tarantool and i tried to ping IPs from windows 7 cmd and it works.
Thank you!
SOLVED
Related
I am trying to get started with java RMI but I keep running in to an error when my components try to bind (or even connect) to the rmiregistry. Whenever I try to bind anything to the rmiregisrty I get a java.rmi.ConnectIOException. I am honestly lost as to what I need to do to fix this.
code
Server
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Server {
public static void main(String[] args) throws Exception {
HelloClass Obj = new HelloClass();
Registry registry = LocateRegistry.getRegistry();
registry.bind("Hello", Obj);
System.out.println("Server is live");
}
}
Client
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client {
public static void main(String[] args) throws Exception{
Registry registry = LocateRegistry.getRegistry();
Hello hello = (Hello) registry.lookup("Hello");
String n = hello.Hello();
System.out.println(n);
}
}
Hello (interface)
import java.rmi.*;
public interface Hello extends Remote {
public String Hello() throws RemoteException;
}
HelloClass
import java.rmi.server.UnicastRemoteObject;
public class HelloClass extends UnicastRemoteObject implements Hello {
public HelloClass() throws Exception{
super();
}
public String Hello(){
return "Hello world!";
}
}
The error
"C:\Program Files\Java\jdk1.8.0_144\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\lib\idea_rt.jar=57417:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_144\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\rt.jar;C:\Users\Roman\Desktop\RMI3\out\production\RMI3" Server
Exception in thread "main" java.rmi.ConnectIOException: Exception creating connection to: 192.168.2.21; nested exception is:
**"C:\Program Files\Java\jdk1.8.0_144\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\lib\idea_rt.jar=57417:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_144\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\rt.jar;C:\Users\Roman\Desktop\RMI3\out\production\RMI3" Server
Exception in thread "main" java.rmi.ConnectIOException: Exception creating connection to: 192.168.2.21; nested exception is:
java.net.SocketException: Permission denied: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:631)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:338)
at sun.rmi.registry.RegistryImpl_Stub.bind(RegistryImpl_Stub.java:60)
at Server.main(Server.java:15)
Caused by: java.net.SocketException: Permission denied: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 5 more
**
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:631)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:338)
at sun.rmi.registry.RegistryImpl_Stub.bind(RegistryImpl_Stub.java:60)
at Server.main(Server.java:15)
Caused by: java.net.SocketException: Permission denied: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 5 more
In Server class you are retrieving remote object registry reference by calling LocateRegistry.getRegistry() method.
As hostname and port not passed hence internally hostname will be derived using java.net.InetAddress.getLocalHost().getHostAddress() api.
As per error message hostname is getting derived as 192.168.2.21, but on that IP attempt to create a socket in port 1099 is giving Permission denied error.
The host from where you are running Server class,
Is that node has IP_ADDRESS 192.168.2.21 ?
You may check using
ipconfig /all
You can check using java.net.InetAddress.getLocalHost().getHostAddress() api.
I think better you may try to pass hostname and port to LocateRegistry.getRegistry("127.0.0.1",1099) method. Changes are in Server and Client code.
Server.java
package rmi.learning;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Server {
public static void main(String[] args) throws Exception {
try {
HelloClass Obj = new HelloClass();
Registry registry = LocateRegistry.getRegistry("127.0.0.1", 1099);
System.out.println("registry=" + registry);
registry.bind("Hello", Obj);
System.out.println("Server is live");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Client.java
package rmi.learning;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client {
public static void main(String[] args) throws Exception{
Registry registry = LocateRegistry.getRegistry("127.0.0.1",1099);
Hello hello = (Hello) registry.lookup("Hello");
String n = hello.Hello();
System.out.println(n);
}
}
I have put all classes in rmi.learning package.
Hello.java
package rmi.learning;
import java.rmi.*;
public interface Hello extends Remote {
public String Hello() throws RemoteException;
}
HelloClass.java
package rmi.learning;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class HelloClass extends UnicastRemoteObject implements Hello {
protected HelloClass() throws RemoteException {
super();
}
public String Hello() {
return "Hello world!";
}
}
Start rmi registry service
start d:\Java\jdk1.8.0_261\bin\rmiregistry
From a command prompt:
Execute Server
cd d:\workspace_europa\StackOverflow\bin
start /B D:\Java\jdk1.8.0_261\bin\java.exe -classpath .;rmi -Djava.rmi.server.codebase=file:rmi/ rmi.learning.Server
Output:
registry=RegistryImpl_Stub[UnicastRef [liveRef: [endpoint:[127.0.0.1:1099](remote),objID:[0:0:0, 0]]]]
Server is live
From a command prompt:
Execute Client
D:\Java\jdk1.8.0_261\bin\java.exe -classpath . rmi.learning.Client
Output:
Hello world!
More investigation:
I was trying to reproduce this issue, I connect to internet via router. Once I connect to wifi then my router is assigning IP address 192.168.0.102.
java.net.InetAddress.getLocalHost().getHostAddress() api return IP ADDRESS as 192.168.0.102
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : xxxx::xxxx:xxxx:xxxx:xxxx%18
IPv4 Address. . . . . . . . . . . : 192.168.0.102
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
If I try to bind rmi service to 192.168.0.102 in port 1099 then it's working fine.
But if I connect to VPN then one new IP is assigned to my host. While connected to VPN, IP 192.168.0.102 is no more resolvable and my machine IP_ADDRESS is getting changed. This time if I try to bind rmi service to IP 192.168.0.102 then getting error java.net.SocketException: Permission denied: connect.
Hence the the error is coming if the IP ADDRESS is not no more applicable for current node.
In many places I have seen people are suggesting to use
-Djava.net.preferIPv4Stack=true also. While running Server.class you may try similar
start /B D:\Java\jdk1.8.0_261\bin\java.exe -Djava.net.preferIPv4Stack=true -classpath .;rmi -Djava.rmi.server.codebase=file:rmi/ rmi.learning.Server
Even some places people are saying about disabling any Anti Virus running on the system, you may check that possibility also.
I have two AWS Instance I1 and I2 having Ip addresses as ip1 and ip2 respectively.What I want to achieve is:
I want to hit a url from I1(using java httpclient) and want that request should go through I2 instance i.e to outside world it should appear that the request is coming from instance I2.
For Example :
I am executing the below-mentioned code from instance I1 :
class Test {
public static void main(String[] args) {
String url = "https://api.ipify.org?format=json",
proxy = "ip2";
Proxy p = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy, 80));
URL server = new URL(url);
Properties systemProperties = System.getProperties();
HttpURLConnection connection = (HttpURLConnection)server.openConnection(p);
connection.connect();
String theString = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
System.out.println(theString);
}
}
The Output should be public Ip of instance I2. But it is throwing the exception:
Exception in thread "main" java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient$1.run(HttpClient.java:515)
at sun.net.www.http.HttpClient$1.run(HttpClient.java:513)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.http.HttpClient.privilegedOpenServer(HttpClient.java:512)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:553)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1199)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:162)
at sun.net.www.protocol.https.HttpsURLConnectionImpl$connect.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at com.exp.Test.main(Test.java:24)
I have googled for the above mentioned use case but was not able to find anything. Any help is appriciated.
This issue is fixed.
Installed squid server on instance I2.
I am new to RabbitMQ and trying out simple example on it.
Below is my java source:
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
public class Send {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
}
}
And am getting below error:
Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:588)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:612)
at .Send.main(Send.java:15)
Any suggestions please?
Do you have your RabbitMQ server installed?
Also do you have the rabbitmq-client.jar and its dependencies on the classpath?
Try running this from your terminal:
java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Send
I'm trying to read messages from my inbox, but I'm keep getting exception "MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 110; timeout -1;"
I disabled my AntiVir and Firewall, but doesn't help.
Below is code and console report:
public class JavaMailPOP3eMail {
private String server = null;
private String user = null;
private String pass = null;
public void sendMail() {
server = "smtp.gmail.com";
user = "user123#gmail.com";
pass = "pass123";
Store store = null;
Folder folder = null;
try {
// get default session
Properties properties = System.getProperties();
Session session = Session.getDefaultInstance(properties, null);
session.setDebug(true);
// get a pop3 message store, and connect to it
store = session.getStore("pop3");
store.connect(server, user, pass);
// get the default folder
folder = store.getDefaultFolder();
if (folder == null) {
throw new Exception("No default folder");
}
// get the inbox
folder = folder.getFolder("INBOX");
if (folder == null) {
throw new Exception("No POP3 INBOX");
}
// open the folder read only
folder.open(Folder.READ_ONLY);
// get the messages and print them
Message[] messages = folder.getMessages();
for (int i = 0; i < messages.length; i++) {
printMail(messages[i]);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (folder != null) {
folder.close(false);
}
if (store != null) {
store.close();
}
} catch (MessagingException ex) {
ex.printStackTrace();
}
}
}
public void printMail(Message message) {
try {
// get header information
String from = null;
from = ((InternetAddress) message.getFrom()[0]).getPersonal();
// print sender details
System.out.println("From: " + from);
// get and print subject
String subj = message.getSubject();
System.out.println("Subject: " + subj);
// get the message itself
Part messagePart = message;
Object content = messagePart.getContent();
if (content instanceof Multipart) {
messagePart = ((Multipart) content).getBodyPart(0);
System.out.println("[ Multipart Message ]");
}
// get the content type
String contentType = messagePart.getContentType();
// if the content is plain text, print it
System.out.println("Content: " + contentType);
if (contentType.startsWith("text/plain") ||
contentType.startsWith("text/html")) {
InputStream is = messagePart.getInputStream();
BufferedReader br = new BufferedReader(
new InputStreamReader(is)
);
String line = br.readLine();
while (line != null ) {
System.out.println(line);
line = br.readLine();
}
}
System.out.println("");
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
JavaMailPOP3eMail mail = new JavaMailPOP3eMail();
mail.sendMail();
}
}
Exception:
DEBUG: setDebug: JavaMail version 1.5.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]
DEBUG POP3: mail.pop3.rsetbeforequit: false
DEBUG POP3: mail.pop3.disabletop: false
DEBUG POP3: mail.pop3.forgettopheaders: false
DEBUG POP3: mail.pop3.cachewriteto: false
DEBUG POP3: mail.pop3.filecache.enable: false
DEBUG POP3: mail.pop3.keepmessagecontent: false
DEBUG POP3: mail.pop3.starttls.enable: false
DEBUG POP3: mail.pop3.starttls.required: false
DEBUG POP3: mail.pop3.apop.enable: false
DEBUG POP3: mail.pop3.disablecapa: false
DEBUG POP3: connecting to host "smtp.gmail.com", port 110, isSSL false
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 110; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:211)
at javax.mail.Service.connect(Service.java:364)
at javax.mail.Service.connect(Service.java:245)
at example3.JavaMailPOP3eMail.sendMail(JavaMailPOP3eMail.java:43)
at example3.JavaMailPOP3eMail.main(JavaMailPOP3eMail.java:118)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:312)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:112)
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:264)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:207)
EDIT:
POP is enabled but still doesn't work
Do you have any other idea what the reason could be ?
DEBUG: setDebug: JavaMail version 1.5.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]
DEBUG POP3: mail.pop3.rsetbeforequit: false
DEBUG POP3: mail.pop3.disabletop: false
DEBUG POP3: mail.pop3.forgettopheaders: false
DEBUG POP3: mail.pop3.cachewriteto: false
DEBUG POP3: mail.pop3.filecache.enable: false
DEBUG POP3: mail.pop3.keepmessagecontent: false
DEBUG POP3: mail.pop3.starttls.enable: false
DEBUG POP3: mail.pop3.starttls.required: false
DEBUG POP3: mail.pop3.apop.enable: false
DEBUG POP3: mail.pop3.disablecapa: false
DEBUG POP3: connecting to host "pop.gmail.com", port 110, isSSL false
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: pop.gmail.com, 110; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:211) at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:211)
at javax.mail.Service.connect(Service.java:364)
at javax.mail.Service.connect(Service.java:245)
at example3.JavaMailPOP3eMail.sendMail(JavaMailPOP3eMail.java:41)
at example3.JavaMailPOP3eMail.main(JavaMailPOP3eMail.java:116)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:312)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:112)
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:264)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:207)
... 4 more
According to this link from Gmail, the server should be pop.gmail.com (instead of smtp.gmail.com) and you have to allow POP access to your account for this to work.
Most people get failed to configured Gmail ID in SMTP .
First you have to do some setting on gmail account :
1) Set less secure app on that account
2) Enable pop from account setting option
3) if it is windows server login gmail account once on the same server.
It will work 100 percent.
Thanks
Sajju
I am communicating using TCP Socket.
While Working, a problem arises
Client can't make 'Socket' Instance.
Strange Point is that (In Server using Python)
Using 'socket' class in python don't cause problem,
but using 'SocketServer.TCPServer' class in python cause problem
This is my environment.
Server : Python
Client : Java / Many Users will try connect.
Server Code (using Python):
SooMain.py
if name == "main":
server = SooServer('localhost', PORT_DEBUG, SooRequestHandler)
server.serve_forever()
SooServer.py
class SooServer(SocketServer.TCPServer):
"This is Server For Project201201"
def __init__(self,
host='localhost',
port=PORT_DEBUG,
handler=SooRequestHandler):
#SocketServer.ThreadingTCPServer.__init__(self, (host, port), handler)
SocketServer.TCPServer.__init__(self, (host, port), handler)
print "SooServer <State> __init__"
self.abort=0
self.timeout=10
def shutdown(self):
SocketServer.ThreadingTCPServer.shutdown(self)
print "SooServer <State> shutdown"
Client Code (using Java):
TestJava.java
public class TestJava {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
try {
String[] aStrData = {
"Test",
"Test" };
InetAddress m_oInetAddr = InetAddress.getByName(DEBUG_ADDR);
Socket m_oSocket = new Socket(m_oInetAddr, DEBUG_PORT); //This Line Makes Exception!!!!!
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(m_oSocket.getOutputStream())), true);
int nNumData = aStrData.length;
out.println(Integer.toString(nNumData));
for (int i=0 ; i<nNumData ; i++) {
out.println(aStrData[i]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Error Code (using Java):
Releated Line : Socket m_oSocket = new Socket(m_oInetAddr, DEBUG_PORT);
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:241)
at TestJava.main(TestJava.java:51)