Jump to content

LAN programming

Blade_792

In my class, at school, we are programming a UDP chat on al lan with a server structure but we have a bit of a problem.

We need a function to have the ip of the client machine and send it without setting it manually, to be more specific if we have 3 client we don't have to initialize a char array with the ip and convert it but have a function that give the ip in char array, string or directly in binary so we don't have to change the code for every client.

Anyone who know how to do this?

 

Link to comment
Share on other sites

Link to post
Share on other sites

I got two ideas off the top of my head

1) Have a server, that tells you about other clients, who have also connected to the server. Just for finding other clients, just like P2P/BitTorrent.

2) Have one client listen and another send a local broadcast message with their IP.

HAL9000: AMD Ryzen 9 3900x | Noctua NH-D15 chromax.black | 32 GB Corsair Vengeance LPX DDR4 3200 MHz | Asus X570 Prime Pro | ASUS TUF 3080 Ti | 1 TB Samsung 970 Evo Plus + 1 TB Crucial MX500 + 6 TB WD RED | Corsair HX1000 | be quiet Pure Base 500DX | LG 34UM95 34" 3440x1440

Hydrogen server: Intel i3-10100 | Cryorig M9i | 64 GB Crucial Ballistix 3200MHz DDR4 | Gigabyte B560M-DS3H | 33 TB of storage | Fractal Design Define R5 | unRAID 6.9.2

Carbon server: Fujitsu PRIMERGY RX100 S7p | Xeon E3-1230 v2 | 16 GB DDR3 ECC | 60 GB Corsair SSD & 250 GB Samsung 850 Pro | Intel i340-T4 | ESXi 6.5.1

Big Mac cluster: 2x Raspberry Pi 2 Model B | 1x Raspberry Pi 3 Model B | 2x Raspberry Pi 3 Model B+

Link to comment
Share on other sites

Link to post
Share on other sites

44 minutes ago, jj9987 said:

I got two ideas off the top of my head

1) Have a server, that tells you about other clients, who have also connected to the server. Just for finding other clients, just like P2P/BitTorrent.

2) Have one client listen and another send a local broadcast message with their IP.

we have a client list for the broadcast messages but the problem is that we, for this specific project, are using a login system so we have to tell the client ip to the server so it can be putted in the list for the broadcast.

the solution are 2:

1) the server check the ip, thats i don't know if it's possible 'cause USP

2)the client tell the server his ip, we are opting for these but the first option is better beacuse in that case we have to add the function on the server code instead of modify the function that create the buffer to send on the client

 

Link to comment
Share on other sites

Link to post
Share on other sites

You could broadcast a message and every recipient running the app responds to it by sending the IP. Or every app simply broadcasts the IP to everyone.

Use the quote function when answering! Mark people directly if you want an answer from them!

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, bowrilla said:

You could broadcast a message and every recipient running the app responds to it by sending the IP. Or every app simply broadcasts the IP to everyone.

I need the c++ functions to have the ip because for thise prject we don't have to know wich machine will be in the chat and can't set in advance

Link to comment
Share on other sites

Link to post
Share on other sites

If you want to determine the IP addresses , you have Windows API functions for that

 

IPv4 only  Windows 2000 and newer : GetAdaptersInfo : https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersinfo?redirectedfrom=MSDN

 

IPv4 & IPv6 : Windows XP/2003 and newer : GetAdaptersAddresses : https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses?redirectedfrom=MSDN

 

It may also help you to read about WinSock 2 API, here's the reference : https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-start-page-2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

My network knowledge is not great but as @bowrilla said you can broadcast a message. Using UDP you can send a message to any local network device.

Some info I found from a quick google search

 

MSDN

Quote

Setting all the bits of an IP address to one, or 255.255.255.255, forms the limited broadcast address. Sending a UDP datagram to this address delivers the message to any host on the local network segment. Because routers never forward messages sent to this address, only hosts on the network segment receive the broadcast message.

 

https://support.biamp.com/Audia-Nexia/Control/TCP_and_UDP_discovery_methods

Quote

UDP stands for User Datagram Protocol and is one of the core protocols of the Internet Protocol (IP) suite. As for the Broadcast term, it describes the process of broadcasting packets to an entire subnet. (e.g: 192.168.1.001 to 192.168.1.254).

 

Now the actual implementation is up to the language you choose and the available tools on it.

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

As a beginner you should try TCP instead of UDP. You cut the hassle of rearranging the packet on arrival since TCP does it for you. Also this provide a live connection which gives you the ip and all you need to create a collection of connected clients and keep track of them.

Link to comment
Share on other sites

Link to post
Share on other sites

On 2/8/2021 at 2:33 PM, Franck said:

As a beginner you should try TCP instead of UDP. You cut the hassle of rearranging the packet on arrival since TCP does it for you. Also this provide a live connection which gives you the ip and all you need to create a collection of connected clients and keep track of them.

since it's a school project i can't choose

Link to comment
Share on other sites

Link to post
Share on other sites

On 2/7/2021 at 12:24 PM, MisterWhite said:

My network knowledge is not great but as @bowrilla said you can broadcast a message. Using UDP you can send a message to any local network device.

Some info I found from a quick google search

 

MSDN

 

https://support.biamp.com/Audia-Nexia/Control/TCP_and_UDP_discovery_methods

 

Now the actual implementation is up to the language you choose and the available tools on it.

my problem is the actual implementation i c/c++

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×