How to detect an server IP from client and connect with that server using TCP/IP? - networking

i have a three system connected in a LAN and one of the system has server program running but the client doesnt know IP of that server. Client has to detect that server and connect with that server . Is it possible to do and whether it can be done using TCP/IP

You could probably send a TCP package to the broadcast address of your network when trying to find the servers ip address.
That way every device in your network receives your package. Then just make the server listen and respond to that package. That way you can easily find your servers IP address without trying to connect to every single IP

Related

If someone knows my external address and port, can public internet computer start a TCP socket towards my computer without router port forwarding?

I'm trying to build a peer-to-peer game, where each player is both a server and a client with tcp sockets. The sockets can connect fine when I'm using local ip:s, but of course fails when I'm trying to use external ip:s.
But I'm thinking that the players should be able to connect to each other if they just knew the external address + port that the router assigns to them.
Setting up port forwarding is out if the question since I don't have access to the players routers.
I'm thinking of having a server in between, just to be able to read the external address and port of the players, and tell the other player about it so that it can connect.
But I haven't found any info anywhere if that's how port forwarding works. If computer A makes a request from a local address and a port to the server, and the router assigns this address + port to an external address + port, and the server tell computer B which address + port to use. Can computer B use that external address + port to connect to the computer A and start a tcp socket with it? Is there any way to know that this external address + port stays the same when another computer makes a request against them?
The problem is that most people don't expose their PC directly to the internet. They have a router that has an external address. When you send a packet to their IP address, it is going to their router. The router doesn't know where to forward it to and what port to use without port forwarding.
So, getting everyone to enable port forwarding is out of the question, as it should be. A simpler mechanism is to have a server on the internet that you control. It has a firewall with port forwarding setup. The clients are just clients, they connect to the server on a port and send and receive info about the current status of the game. That way, everyone has real-time updates on their local game engine. Plus, this way is much easier to program and implement.
No, TCP doesn't work like that.
The source port that has been used to talk to the rendezvous server will be transient and specific to that particular initial TCP socket connection and can only be used as a destination for return traffic on the same connection from the rendezvous server, and can't be used by a third party to make new inbound connections.
The typical (only?) practical solution when NATs are involved and port forwarding is not available is to have that central server relay all messages bidirectionally between the peers.
Hole punching is what I was looking for.
https://en.wikipedia.org/wiki/Hole_punching_(networking)

connecting to another network present in one network

I have been trying to create a server in one network but the people in another network cant connect to my server? Even though my IP is dynamic (dhcp :yes)
I want to create a server in one network but want to connect people to that server present in another network. I started a server "eg: 103.251.9.85:27015"
even though my IP is dynamic, they can't connect to my server? Help me ...
who ever knows my IP address and port number will connect to my server, but when I am starting a server they cant connect.
Your server needs a DNS record.
DHCP is great for allocating an IP address - but you then have to manually tell everyone what the IP Address is.
You should define your Server in your DHCP configuration, assuming that there is a DNS Server also.
By default the DHCPD informs the DNS Server - assuming they are both under your control.
First ensure that you have network connectivity between the nodes - there can be NATs, Firewalls and a lot of different reasons why you can not connect. My advice for you would be to try and use netcat.
Once you have netcat on your computer - start it in a server mode. Then ask your friend to download netcat on his/her computer and connect to your IP address. If you can establish connection - great. Then make a question regarding your server program. If netcat fails - then there is network connectivity issue and you will find better help for those issues in the power user or network engineering Stack Exchange sites.

TCP/IP connection timed out

I wrote a java program of TCP/IP Client which is supposed to read data from TCPIP server device.
Problem is when I give the IP and Port of the Device, java gives error of "Connection Time out". Obviously this is problem of not connecting to that Device.
I want to know if there is way to know where the problem is? Whether that TCPIP server device is not reachable (if no, then how to check it )
whether Its the router / network issue that TCPIP Client and Server has to be on same network or use same router to communicate. OR Just IP:Port is enough.
How on my computer may I know that TCPIP server device is turned on and streaming??
P.S. That TCPIP Server device can also be connected with blutooth connection. can i read streaming through blutooth in Java?? if yes what/How should I do it?
I want to know if there is way to know where the problem is? Whether
that TCPIP server device is not reachable (if no, then how to check it
)
Use telnet from the client - it will try to connect to the remote server at the port that you specify. For example telnet google.com 80 attempts to reach google.com on port 80. You could also use an IP address in place of "google.com". If you are on a windows box, you might have to enable telnet first.
You can also use netstat on the server. It should say the ports that are currently open and the state that they are in. For example, your Java server program should be listening on the port, so the state should say LISTEN.

Configure a server inside LAN

I'm currently working on my group voice chatting program. This is my plan:
Build up a server on 192.168.1.125. Listen to port 3490 and forward it to the router.
Clients connect to the server and get the user IP list(Whenever a client connects to the server, its IP address is recorded by the
server)
Clients communicate with each other using UDP multicast(is this ever possible across the router?).
But now I'm running into troubles. If a client inside the LAN, e.g. 192.168.1.120, connects to the server, it's taken down as 192.168.1.120, which won't work for clients from WAN.
I'm wondering if there is any way to convert the LAN IP to public IP? (this might have something to do with the router, I think)
Thanks.
You will have to be prepared for the case where direct client-to-client communication fails. Relaying through the server or NAT traversal/penetration may be necessary. Significant expertise is required to do this correctly.

What happens when two processes bind to a port and communicate with the same server?

If two processes both use a shared local port to connect to the same remote port of the server server, what happens when the server tries to respond to one? Or is there a mechanism to prevent this?
I assume you're asking about TCP here. When the two processes connect to a single remote port, they will be using different local ports. That is how the server distinguishes the connections. A connection has four parts that uniquely identify it: source port, source IP address, destination port, and destination IP address.

Resources