How does the client connect to the server with EC2 - java

I have just put my socket server on Amazon EC2 and the server is up and running. The port for the server socket is ss = new ServerSocket(30001);. What do I set the socket port inside my client class to? It is currently on local host. socket = new Socket("localhost", 30001); The amazon EC2 address is
ec2-user#ec2-34-253-76-28.eu-west-1.compute.amazonaws.com
Do I just replace localhost with this?

If the client is remote (not on the same host as the server) then, yes, use the host's DNS name or public IP address.
You will also have to allow inbound connections to the EC2 instance hosting your server application. Ensure that port 30001 is open for ingress to your client's public IP address (or to the world by indicating 0.0.0.0/0 as the source CIDR). You do this in AWS via Security Groups.
If you expose your server to the world, then you should implement (at least) some form of authentication for your clients.
A few things to check, if your client cannot connect:
Is your server socket bound to 0.0.0.0 (or the public IP associated with the EC2 instance)?
Is your server app running?
Does netstat show your server app listening on port 30001?
Did you add a security group to the EC2 instance and add an ingress rule allowing inbound traffic from your client IP (or the world) to port 30001
Is the client running on a network (e.g. corporate) that blocks outbound port 30001

Related

How can I connect to server socket running inside a docker container from another machine?

In one system, I am having a docker container, In that a Server Socket was ready to accept the client socket. So, How can I connect to the server socket from another system?
The container IP and port was: 171.18.1.4:9090
Server socket port was: 3333
How can I connect the client socket to the server socket?
Note: I am using java for this program
You should be able to do that by sending http requests for example via curl:
curl -X GET http://your.ip.address.sth/9090
Bear in mind that here the address is the ip address of your machine and not of the docker Container. Docker operates in private network and publishes a port to your computers network. So just google „what is my ip“ and google will tell u ur machines public ip.
I am assuming 9090 is the port your docker container has published

How can I connect to my server in my own machine from a client in another pc?

Im making a client/server app just for learning purposes, and i want my Client to connect the server (which is running in my pc) from another pc.
Right now im trying to use the server's pc public ip (which I got with whatsmyip.org) in the Client socket: Socket sock = new Socket(HOST, PORT); where host is the public ip of the server's pc.
When I was testing it with localhost and the client running in the same pc, the connection worked.
I already oppened the port im using in the Server pc and added firewall rules, including router's firewall. So any of my firewalls should be blocking the connection to the port im using.
I read in another question this (it was an example): "Your Server PC is in New York with an IP 192.168.1.121, that is behind a router with internal IP 192.168.1.1 and public IP 40.20.26.63. You will need to make sure that you go into the router and forward port 8084 (TCP) to internal address 192.168.1.121 (the internal Server PC)." How can I do that? I know the public IP and the internal IP of the server, but I dont know what IP I need to type in the Client Socket.
Thanks in advance.

Connecting to a java socket using a domain name and no port

I am trying to connect to my own server socket using only a domain name. I own the domain and have set up a subdomain that goes to the Server Socket's ip and the port. How would I only use the domain name in the Socket constructor to connect to the server socket? Thanks!
You can't connect a socket with no port. When you connect with a protocol and don't specify a port (in a web browser for example http://yourweb.com) the port is inferred by the protocol http=80. If you are port forwarding to a sub domain, which I'm guessing is what you describe, there is always a port for the incoming connections ie. http://yourweb.com:80 -> http://sub.yourweb.com:8080.

How can I get the real IP address of Client behind F5 loadbalancer with Java socket

I am developing a Java application. The client sends socket request to the sever after the F5 loadbalancer. The server should record the IP address of the socket request. How can I get the real IP address of the client instead of the IP addreess of the F5.
If you are using SNAT, your Virtual Server must be configured with an HTTP Profile, and this profile must have the Insert X-Forwarded-For enabled. As simple as that.
Of course this means the server must be able to use this header.
If the loadbalancer doesn't use any SNAT, you would already see the client's IP.

connecting to a remote java application

I have to build a server/client chat room in java as a school project, and I want to know if I can connect to that server from the world network (not local network) using the IP address and ports (I wanted to host it but I realized too late that I should have built a web app not a desktop one). My app is using Transmission Content Protocol(TCP) sockets. I have tried to connect to the app by using the public IP and the port that I have opened in firewall. I can post the code if needed. Thanks in advance
If your networks firewall settings let you do it, of course you can connect.
Now, your computer has an internal ip address, which is like 192.168.xxx.xxx and your router has an external ip address which is unique.
Set up your router to forward connections. Steps to do it may change for each router but the point is to forward all connections coming to this router with a port number you have declared, to a internal ip address and a port number.
In your client side, your connection statement will have your external ip adress and the port number you have written in your router settings. In your server side, it will listen your internal ip address and the port number your router forwards to.
To be clear;
Client ---"xx.xx.xx.xx:9999"---> Router ---"192.168.xx.xx:8888"---> Server
As you see above, the router forwards all the connections coming to 9999. port, to 192.168.xx.xx address and 8888. port.

Categories

Resources