hiho,
i intend to develop just a litte network application, something like a chat. so i downloaded xampp for windows and installed it (also as service), mysql included. well, i started the apache (and mysql) as service and just wrote the short line in java:
try {
Socket sock = new Socket("127.0.0.1", 21);
System.out.println("connection established");
} catch ( UnknownHostException e ) {
System.out.println("Can't find host.");
} catch ( IOException e ) {
System.out.println("Error connecting to host. " + e.toString());
}
but directly i got the answer:
Error connecting to host. java.net.ConnectException: Connection refused: connect
the server is runnin'. the localhost is accessible on the browser.
did i forgot something? any ideas?
In your java code you're trying to connect to port 21 (ftp). Don't know what you want to do, but perhaps you should try port 80 (http).
Did you download and install the Tomcat add-on for XAMPP? It's not part of the default install.
After it's extracted into the XAMPP folder you have to run first setup_xampp.bat and then tomcat_start.bat.
Also, Tomcat in XAMPP will use the 8080 port by default.
Related
I have a problem when I try to connect to SQL Server with Java. I have the next error:
The connection to the host DESKTOP-C0SCI39, named instance failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
My firewall is off and I don't know what is wrong(mssql-jdbc-8.4.1.jre14 is included). This is my Java code:
String url = "jdbc:sqlserver://DESKTOP-C0SCI39\\;databaseName=students";
try {
Connection connection = DriverManager.getConnection(url);
System.out.println("Connected to MS SQL");
} catch (SQLException throwables) {
System.out.println("Error!");
throwables.printStackTrace();
}
Try this solution, I have ran into similar problems in the past and have found that these help.
Check that the JDBC Driver is imported in the project. (Preferred - 5.1.48)
Check that your SQL Server is up and running (Check if SQL Service is running)
Check if you entered your connection string properly
eg: private String URL = "jdbc:mysql://localhost:3306/dbName"; //database url
Try adding a useSSL=false to the end of your connection string dbName?useSSL=false
Open your server with a server management software such as SQL Server Management Studio to see if your SQL Server is working as it should
Your database is not running where you think it is running. Verify the port and location of the server and try again.
I'm currently trying to do some network coding for an android (java) application and I'm facing some problems. I use the Apache library commons.net in order to establish an ftp connection to a server I'm hosting for file transfer to the android unit. this is my code:
public class Server {
public static void main(String[] args)
{
String username = "Username";
String password = "Password";
String host = "AddressString";
FTPSClient ftps;
ftps = new FTPSClient();
System.out.println("trying to connect...");
try{
System.out.println("trying to connect...");
ftps.connect(host, 21);
System.out.println("Connected");
System.out.println("logging in...");
ftps.login(username, password);
System.out.println("logged in!");
ftps.enterLocalPassiveMode();
catch (IOException ex) {
System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
} finally {
try {
if (ftps.isConnected()) {
System.out.print("LOggin out");
ftps.logout();
ftps.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
System.out.println("Terminated");
}
}
The program never gets passed the line "ftps.connect(host, 21);", with the error "Connection closed without indication", I do belive I have configured my server correctly since I can connect to it via "Putty" from another network etc. What am I missing here?
Note: I am not trying to connect through an Android device, I'm currently using eclipse for testing.
"I do belive I have configured my server correctly since I can connect to it via "Putty" from another network etc. What am I missing here?"
The "putty" utility talking to an SSH server on port 22 not to an FTP server on port 21. You can say that basic network connectivity / routing appears to be working, but that's not necessarily enough.
Possible problems you may be having include:
the FTP port being blocked by firewalling on the client, the server or somewhere in between, or
the FTP server may be configured incorrectly.
I noticed that the client is trying to use FTP/S but it it using the default port for FTP (21) not FTP/S (991). This is not necessarily wrong (see https://serverfault.com/questions/10807/what-firewall-ports-do-i-need-to-open-when-using-ftps for details) but maybe you should check that your server is configured to support explicit FTP/S.
I would advise:
look at the server and client side logs for clues
temporarily turn on "debug level" logging (client & server side)
see if you can establish a raw TCP connection on port 21; e.g. using telnet <server-host> 21
try changing the client to use FTP rather than FTP/S
if all else fails, try using a packet sniffer to capture the network traffic.
UPDATE
... it seems i confused sftp with ftps ...
Yes, they are very different. SFTP is in effect FTP tunneled over an SSH connection. It requires a client-side library that understands SSH.
So if you are trying to use FTP / FTPS client-side libraries and settings to talk an SSH (SFTP) service, you are probably failing because port 21 is blocked (which it should be if there is no FTP service) or because no FTP service is running (which should be the default for a typical out-of-the-box Linux server).
On my company network we run Remedy 7.64 and want to create Incidents automatically. I setup the development environment using IntelliJ IDEA and the ARAPI-files for my server version. We have no administration access to the server to change anything over there.
The error says
ERROR (90): Can't connect to AR System-Server; Connection refused:
connect <host>.
Mysteriously i can connect to the Web-Interface using Chrome, i can ping the host, i can access it via the Driver & the official Remedy Client and the java tool can get the source code of the web-interface of it as well, so it obviously is possible to connect to the host but the difficulty is somewhere else.
This is my simple demo file
import com.bmc.arsys.api.*;
public static void main(String [ ] args)
{
ARServerUser ctx = new ARServerUser();
ctx.setServer("<server>");
ctx.setUser("<user>");
ctx.setPassword("<pass>");
try {
ctx.login();
System.out.println("works");
} catch (ARException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
This is the list of dependancies
1.8 (java version "1.8.0_65")
[Module source ]
groovy-2.4.5
log4j-1.2.14.jar
arapi7604_build002.jar
You have to provide port number in which AR server is listening on. "ERROR (90): Can't connect to AR System-Server; Connection refused: connect ." means that the server refused to connect as you haven't mentioned the port number to connect. Normally people use 37000 as the AR server port number, but you have to check with your Remedy Admin to know this.
I just came across the same error. My issue was that I tried to connect using the full url as <server> ("https://..."). Using just the name of the server worked.
I'm working on an openshift tomcat project by using mysql as backend I am trying to connect database and it is not connecting and shows error message "Communications link failure Last packet sent to the server was 0 ms ago" I have connected database using this code
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException ex){
//return(ex.getMessage());
}
con = DriverManager.getConnection(MYSQL_DATABASE_HOST,MYSQL_USERNAME,MYSQL_PASSWORD);
} catch (Exception ex) {
return(ex.getMessage());
}
return "success";
I've provided the database url by hardcoding the database IP and port,when I print System.getenv("OPENSHIFT_MYSQL_DB_HOST"); I'm getting null value. please tell me anyone the error
the problem you are facing occurs when your java code is unable to connect to MySQL server. There is one more way, check if your MySQL is up and running. You can get your MySQL server's ip by
rhc port-forward -a <mysql_gear_name>
You can then explicitly give that IP in DriverManager.getConnection
From the command line, run rhc port-forward to access databases or internal ports directly.
Eg :
rhc port-forward -a <name of the gear including mysql db>
I trying to conncet to my MySQL Database hosted in a virtual machine, but it doesn't work
for me.
Here is my setup:
Newest Ubuntu Server witch Apache2 mysql installed and is working
Database "feedback" with the table "test" set up and filled with test data
The network adapter is bridged. The IP of the server is (if I type in ifconfig) 10.0.0.1 and the IP of my pc is 10.0.0.4.
Port 3306 was manually opened. The jar mysql connector java 5.1.21-bin.jar is a Referenced Libary
Here is the Java Code:
import java.sql.*;
public class Main {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Sucess");
Connection con = DriverManager.getConnection("jdbc:mysql://10.0.0.1/feedback","root","myrootpassword");
con.setReadOnly(true);
} catch (Exception e) {
System.err.print("NO CONNECTION");
}
}
}
I hope that someone could help with this, because I'm working on this problem for a while.
Thanks
Just two ideas:
Is MySQL configured to listen on all addresses and not only local ones ? What's the value of the bind-address configuration directive ? 0.0.0.0 means "listen on all interfaces", while 127.0.0.1 means "listen on the localhost interface, for access from this host only".
Maybe you can extract some details about the issue in your catch statement ?
Hope this helps !
If i am correctly understand a question ,To connect VM database,then check for the following steps
1.jdbc:mysql://10.0.0.1/feedback.
2.Make sure there is no firewall blocking the access to port 3306.
3.make sure the user you are connecting with is allowed to connect from this particular hostname.