Derby documentation says
derby.drda.host=hostname
The property listens to a host for network connections i.e. accepts
connections from them. If 0.0.0.0 is specified, connections from any
host is accepted.
Now, I have three remote computers, hostA, hostB, hostC.
My derby server is running on hostA.
I want derby server to listen for connections from hostA, hostB, hostC
So, I wrote
props.setProperty("derby.drda.host", "hostA hostB hostC");
However, this does not work. Is there some other way ?
Edit:
When I set the property as
props.setProperty("derby.drda.host" , "hostA");
then hostB and hostC are not able to connect to server. They get below exception
java.sql.SQLNonTransientConnectionException: java.net.ConnectException
: Error connecting to server hostA on port 8,888 with message
Connection refused: connect.
However, when I set property as
props.setProperty("derby.drda.host" , "0.0.0.0");
then all hosts (hostA, hostB, hostC) are able to connect to the server.
I believe you've misunderstood what this property is used for. This is so that you can tell Derby on which IP of the server to accept connections, if you have multiple network interfaces. (A lot of servers have more than one network card, or are connected to several networks at the same time and thus have several IP-s).
The default setting of 0.0.0.0 means that it should accept any connection being requested on any of the server's IP-s. If you set this value to something other than 0.0.0.0, it will listen just for connections targeting just that IP.
This does not limit the client connections based on their IP.
I believe you need to have the following set:
System.setProperty("derby.drda.startNetworkServer", "true");
In order to start Derby as a network server (and not just run it in the JVM, as I believe the default behaviour was).
Related
I've been reading this socket tutorial by Oracle and stumbled upon the following text:
If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client. It needs a new socket so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client.
Now if I'm not wrong then the port size is 16 bit which limits the max no of ports around 65K. This means that a server can't handle more than 65535 connections at any instant if all of it's port are bound to some client local port. While some answers like this on stackoverflow suggest that there's no limit on active connections. What is true about this and what is wrong?
Edit 1: If indeed a server can't handle more than 2^16-1 connections, then how do websites like Google handle this limitation?
A unique TCP connection is defined by a unique combination of client IP, client port, server IP and server port. For a specific service server IP and port are constant (i.e. port 80 for HTTP), but client IP and port can vary. Since the port range is only 1..65535 this means that the server can only handle at most 65535 different connections from the same client IP address at the same time, because these are all possible unique combinations of the connection tuple when only the port can be changed. But, if there are multiple clients with different IP addresses this limitations applies to each of these clients separately. If you then look at the amount of different possible IP addresses (IPv4 and IPv6) you'll see that there is essentially no real limit of how much connections the server could handle in theory.
In practice each of these TCP connections takes memory at the server since the current state has to be kept. Additional memory is needed in kernel and application for file descriptor and application protocol state etc. This means that there is a practical limit based on the resources of the machine which might be less then 64k but also way more, depending on the system and its configuration.
They use something like NAT (network address translation) for your ISP.
You can access different computer behind your router because your router maps the routes to the PCs internally.
E.g. Google data center does the same thing. Mapping "Google.com" to different internal server allowing them to accept more than 65k connections in total.
Alright, I have a java server setup using port 6567 and IP address 0.0.0.0 as to accept any connection. When I attempt to connect over my local network (192.168.1.15) I am able to connect just fine using the server. However when I switch to a non-local IP address (my routers public IP) I am unable to connect to it.
I have the router port forwarded and the proper rules in place on my firewall/etc. Is there any limitations on Java connecting in this fashion? I'm able to connect externally but not internally. Any thoughts on what might be causing this problem?
I'm starting to think it might be a router-specific problem, being that it could be rejecting the connection but I am unable to test that currently.
Turns out it was just the router itself that rejects internal connections using an external IP address. My personal fix was to just add a bit of testing code that automatically changes the IP if on a local machine to 127.0.0.1 rather then the external IP.
Worked flawlessly both on my own PC and having people connect externally once I set that up.
Hmm I'm not sure about it but maybe that will help.
Most probable, Your ServerSocket gets bound to a local IP address (e.g. 0.0.0.0) and ServerSocket binds to the port address there; and wouldn't respond to any requests coming from an IP address. Try new ServerSocket(4444, 50, InetAddress.getByAddress(new byte[] { YOU IP ADDRESS }).
or check again firewall
edit: Tell me how did you tried to connect from other IP than local?
I have proxy server (on windows machine) that accepts client requests (using java sockets) and I have several internal nodes(unix machines) for processing these requests (in local area network). How to bind the incoming socket connection to a different machine on different port ?
for example I have an incoming connection from client (xxx.xxx.xxx.xxx:5000) to my proxy server (yyy.yyy.yyy.yyy:6000) and I want to bind this TCP Connection to a node on (zzz.zzz.zzz.zzz:7000).
Please let me know different possible ways in achieving this scenario ?
Thanks in Advance !
You cannot bind a connection to another machine. A proxy is supposed to:
accept an inbound connection from a client
create its own client connection to the next server (typically the client would specify this, unless you handle this in your proxy's configuration)
pass data back and forth between the two connections as needed
So, a client would connect to your proxy at yyy.yyy.yyy.yyy:6000, then your proxy would connect to zzz.zzz.zzz.zzz:7000 and start monitoring both connections for inbound data. Any data received on either connection would need to be sent to the other connection. Repeat until one of the connections is closed, then close the other connection.
I have an server process with internal registry (on an Amazon EC2 instance). The server starts correctly and the registry binds itself to port 1099. If I use netstat I can see that it is bound:
tcp6 0 0 :::1099 :::* LISTEN 0 3258 765/java
Additionally I've added Port 1099 TCP to the security group of the instance. If I sstart nmap on the host, it lists the port as open:
Host is up (0.061s latency).
Not shown: 997 filtered ports
PORT STATE SERVICE
22/tcp open ssh
1098/tcp closed unknown
1099/tcp open unknown
However, it is no possible for the client to connect to the server. After a while I get an java.net.ConnectException: Connection timed out exception.
What am I missing? Are there other ports that need to be opened?
You need to make sure that your exported objects use the same port as the registry (or some other visible port). most likely you are connecting to the registry and then not able to connect to the port on which the object is exported. finally--i'm not super familiar with ipv6--but you should verify that you are binding to the external network interface and not a loopback interface.
Well, im pretty sure I had to open another port. Because when I opened all ports for incoming traffic, it worked.
Since this was only a test setup i lived with that and simply restricted incoming traffic to well known sources.
I connect to mysql database with java coding and give input as hostname,user,password.
its able to connect and reterview the data. But when i activated firewall , its not able to connect database.
You should configure your firewall to not block the port number used by MySQL for communication (3306 by default) for the application being executed or for connections coming from the machine where you are running your program.
Your firewall blocks the incoming connection to port 3306. Set-up your firewall to allow connection on that port.