0

I'm developing a messaging system in Delphi. I'm using TcpClient(Sockets) and TcpServer(Sockets) IPv4 on a LAN and DHCP server through a modem.

  1. This means all computers with get example 196.168.0........ IP addresses. One of these computers will be the sever in my case. Whats a way to identify my special server as most modems support 254 computers (is that correct).

  2. With nonblocking (Sockets) transferring streams how do I at the sever do I manage/Identify a stream with who sent it.

  3. what are preferred ports that people should use, as email, HTTP, FTP, SQL ports should be avoided, so I want to use a port that is uncommonly used to remove conflicts. I have not done this before and cannot find ideal code.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    If you have more than one question, then you should ask more than one question. And each of those must be specifically about a problem you have with a clear self-contained scope. – Jerry Dodge Jul 11 '16 at 01:12
  • 1 - Modems aren't DHCP servers, they're physical layer devices. The number of IP addresses provided to a DHCP scope is entirely independent of your modem. What do `identifying your special server` ? 2- Identify by the client's IP and port (socket). 3- Ports 0-1024 are used for "well known" services and should be avoided. You should provide some code and give an idea of what you're tried / researched because the question is riddled with unknowns and lacks detail. – Mvarta Jul 11 '16 at 01:16

3 Answers3

0

1) The number of computers supported will depend on the router part of your modem. Your server could be assigned a specific IP address (all routers I used have this facility). Or each client could broadcast a message to all ip addresses and see which IP address it gets a reply from.

2) You will have to establish a connection between the client and the server before sending the stream of data - the client will identify itself by IP address. If you want more than that, like computer name or user name that will have to be sent in the stream data.

3) Don't use port number below 1024.

Michael Vincent
  • 1,620
  • 1
  • 20
  • 46
0

Thanks Michael Vincent, 1/ I do not want users to set IP addresses if possible. There must be a way to get the computer IP. Take the first 3 IP numbers, search for the server where the server replies with 256 requests from the client with the last IP. A 100mb/s LAN should enable a reply within 1/2 second today. 2/ ports over 1024 ok, I understand a port value is a word size I see MySQL often use 3306 but what is clear port space (like clear air space for a plane). I read the internet ports used by companies and nothing is unused. Old MySQL that no ones uses is 3300 is that safe to remove conflicts or am I better to send a ID string looking for a server, and reply with a server ID string to obtain ID.

Lex Dean
  • 9
  • 5
  • 1/ Do consider the broadcast suggestion, too. 2/You have many, many numbers to choose from - don't use ones that are famously used already, if on legacy software. You could try 4242 - I've not heard of that be used. Don't hard code it - make it possible to change it ny your users on the odd occasion it might be necessary. – Michael Vincent Jul 11 '16 at 14:32
  • Thanks SilverWarior opens my eyes, can a Computer on a LAN identify how many available IP addresses with software. Michael Vincent I understand Ethernet is a broadcast method but the computer with the correct IP receives the data. It would be magic to broadcast requesting my server on a port. otherwise I have to search 1 to 256 on the last IP address no for the server to reply. – Lex Dean Jul 11 '16 at 23:42
0
  1. The number of computers in a single network is determined by the networks NetMask. Most home based LAN's use netmaks of 255.255.255.0 which indeed means that there can be up to 254 computers connected to such network where only last part (byte) of the IP address can be changed and first three bytes stay the same. But if you change your networks NetMask to 255.255.0.0 for instance then you can have up to 65535 computers connected to such network and the last two pars (bytes) of their IP can be changed.
    You can check different possible network configurations with TIdNetworkCalculator component that allows you to preform validity check of any IP address based on certain NetMask. Or if you want it can list all available addresses as List of Strings.
    Also you might want to read more about NetMask and creating subnetworks on the web: https://en.wikipedia.org/wiki/Subnetwork
  2. As it was already sad you should exchange some idendtification data between the server and the client on connect. This can also be useful in case of connection loss because only relying on IP address is not enough since the IP address can change (not likely on LAN)
  3. As for which port should you use. It depends on many factors. Main factor is firewall configuration on your targets computer. Also be aware that some routers may have their own built in Firewall which could also be blocking certain ports. Second factor is whether specific port is already used by some service on your network.
    In any case I recommend you design your compunication protocol in a way that it can be easily identified because this way you are allowing yourself to filter out possible interferences from some other applications that might try to use same port as your application does.
    Also you can find more suggestion about this specific question on links bellow:

Assigning TCP/IP Ports for In-House Application Use

Best TCP port number range for internal applications

Community
  • 1
  • 1
SilverWarior
  • 7,372
  • 2
  • 16
  • 22