Java Socket connection refused with my Public IP - java

I have a client server architecture project in android. I cant connect with my public IP to server. I closed firewall, and did the port redirection for server. My friend can connect from outside to my server, but i can't, why? how can it be?..
Thanks..

Which OS are you running your client server code. If Windows, look for c:\Windows\System32\drivers\etc\hosts, if it's linux go the /etc/hosts/ file
Open the file with sudo privileges.
Format:
<IP> <HOSTNAME>.<DOMAIN> <ALIAS>
Example:
127.0.0.1 localhost.localdomain localhost
Add your IP here with domain name. Your Domain Name can be anything and try again. Also your question is a bit vague. Please add more details such as your os env and what exactly are you trying to achieve?

Related

Socket IO - how to configure and connect to netty socket io server on a secure domain

I need some help with doing netty socket io over https. I have got it to in my local env but not on a server with secure domain. The server starts but client isn't able to connect. Tried by starting the socket server with IP as well as domain name. For the server to start with domain name as hostname value in setHostname method, I added an entry in /etc/hosts file as following
127.0.0.1 localhost example.com
Socket server started by giving example.com as hostname but client isn't able to connect using the same hostname over https as following
var socket = io.connect('https://example.com:10443')
Tried with options - { secure: true, reconnect: true, rejectUnauthorized : false } too but the same issue.
On server side my configuration is as following
Configuration configuration = new Configuration();
configuration.setHostname("example.com");
configuration.setPort(10443);
configuration.setKeyStorePassword("mypassword");
InputStream stream = getClass().getClassLoader().getResourceAsStream("keystore.jks");
configuration.setKeyStore(stream);
The jsk file was created using keytool command for the same domain (example.com)
Is there something more to be done for the port - 10443 to be used by the socket server? Or is there any other configuration to be done?
Got the solution! I had not mentioned that the domain was set up on cloudflare. Here the issue was with the port I used - 10443. It's not supported by cloudflare. Changed it to 8443 and it worked!
For those who come across this, please find here the list of supported ports that Cloudflare work with. May save much of your time unlike me.
Also, please note that I used my public IP as hostname in setHostname() method so that I don't need anything added in my hosts file. Then gave the actual domain name with https on client side to connect to the server. That's it. Thank you all!
Sandeep

Java Connection to MySQL-Database over HTTP or HTTPS

I'm working on a little java project and I have a problem.
The Mysql-Protocol is blocked by the Firewall and the only ports I'm able to use are 80 or 443. Is there any way to connect to my database over these ports? Acutally I'm using the mysql-connector library for java to connect.
You can change the port of MySQL.
change the port in /etc/mysql/my.cnf
example :
cp /etc/mysql/my.cnf /etc/mysql/my-3307.cnf
//edit my-3307.cnf, for example
port = 3307
basedir = /var/lib/mysql-3307
datadir = /var/lib/mysql-3307
//end-edit
mysql_upgrade --defaults-file=/etc/mysql/my-3307.cnf #checks the syntax and creates the dirs you need.
#start mysqld
mysqld --defaults-file=/etc/mysql/my-3307.cnf
source : http://dev.mysql.com/doc/refman/5.1/en/multiple-servers.html
PS : 443 is default https port. It is not advisable to use this and 80(http) port.
Maybe you can change the MySQL port to 443;
But, i think it's bad...
I recommend you to setup SSH server on 443 port and use it for tunelling traffic to your database and any other service.
Here's how you can tunnel traffic from your local machine to remote database:
ssh -L 9000:localhost:3307 user#1.2.3.4 -p 443
Now you can connect to database, like you have it running locally on localhost:9000. All your traffic to SSH server is encrypted. Check this article for another examples.
You can also check chisel project, however I'm not very familiar with it.

connection refused in java amazon SDK for S3 service

i'm coding a command line tool to manage the S3 service. on my local machine, everything works but on the server where it should be executed, fails with the following message:
Error Message: Unable to execute HTTP request: Connection to http://s3.amazonaws.com refused
i make the connection with the following code:
s3 = new AmazonS3Client(credentials,clientConf);
clientConf only sets the protocol to HTTP, as i suspected that maybe could be a problem to connect to HTTPS but i'm having the same result.
now, the server have the following configuration:
debian 6 64 bits
LAMP installed from source
openssl installed from source
java installed from distribution packages packages
this is the network configuration:
auto eth0
iface eth0 inet static
address XX.XX.XX.XX
netmask 255.255.255.255
broadcast XX.XX.XX.XX (same as address)
auto eth0:0
iface eth0:0 inet static
address XX.XX.XX.XX
netmask 255.255.255.255
broadcast XX.XX.XX.XX (same as address)
auto eth0:1
iface eth0:1 inet static
address XX.XX.XX.XX
netmask 255.255.255.255
broadcast XX.XX.XX.XX (same as address)
post-up route add 10.255.255.1 dev eth0
post-up route add default gw 10.255.255.1
wget, telnet, curl, everything works, except this, i have 3 network interfaces as i have 2 SSL and another ip for the other sites.
how i should configure the clientConf to make this work? is a java problem? a network problem? at least, how i can get more debug info? i tried to catch the AmazonClientException exception but doesn't work.
Thanks in advance :)
Regards.
This has been reported as a bug in the Amazon S3 API. Quoth ZachM#AWS:
This appears to be a bug in the SDK. The problem is that the client
configuration object is shared with the Security Token Service client
that DynamoDB uses to establish a session, and it (unlike Dynamo)
doesn't accept the HTTP protocol. There are a couple workarounds:
1) Create your own instance of STSSessionCredentialsProvider and
provide it to your DynamoDB client, or
2) Instead of specifying the protocol in the ClientConfiguration,
specify it with a call to setEndpoint("http://...")
We'll discuss solutions for this bug.
I would recommend using one of the workarounds for now. Good luck getting your connection to work successfully.
(Additional documentation and workarounds)

Connection problem with sockets in java

i tried this code:
http://programming-guides.com/java/tcp-client-server-chat
(full example)
and it's working but when i switch the "host" int the client side to an external IP (insted of localhost) it give me this error:
"Cannot get IO for connection to.."
i treid to switch the port but it didnt work..
Is the server running on that remote machine? Is the port open in the firewall?
Try to netcat to the remote host. If you get an connection the example maybe wrong. If not, you cannot connect to that host: host not exists, not listen on that port, port is filtered, etc, etc.

UnknkownHostException

Please help;
Am trying to deploy a web application.
The build is returning successful,and am not getting any errors on the sever.log
however am getting a http 503 error:the requested service() is not currently available
and also my
Java DB Database Process has this message
Warning: UnknkownHostException: intracare: intracare.
Could not listen on port 1527 on host localhost.
am using glassfish v3 prelude
Possibly you already have another application (perhaps another JavaDB instance?) listening on port 1527 - that could explain the "could not listen" message. Use netstat to check.
I think that UnknownHostException is related that intracare can't be resolved to an IP.
I would:
Ping that host.
Check C:\WINDOWS\system32\drivers\etc\hosts or /etc/hosts files.
Regards.
Check the DNS settings on the host. Your short names do not resolve correctly.
Mayby string you are typing as a host name is wrong? Maybe it is firewall problem?

Categories