none
Application using two IP adresses RRS feed

  • Question

  • Hello all,

    I have developed an application using two different connections. It runs on a machine with two different RJ45 plugs, two different Ethernet cables.

    • One connection is a regular database server connection. I use standard SQL Server connection strings to access a database located on a server.
    • I use the second connection to access a device through sockets. My application contains a  socket Client which connects to the device and receives answers.

    Both connections work well when run independently. But when both connections are active, there seems to be some mixup... I have several questions for experts :

    1. Do I need to use two different IP addresses ? Or is it sufficient to use two different port numbers ? The port number on the second connection (sockets) is 508. What port number is used to connect to SQL server ?
    2. Do I need to use fixed addresses ? Should I activate DHCP in one connection, in both ? Does it make any difference ?
    3. What are the necessary measures to make sure there will be no interaction from one connection to the other ?
    4. If I disconnect both cables and reconnect each of them in the other plug, how will the system figure out what goes where ? This puzzles me...

    Thanks

    Wednesday, June 12, 2013 8:00 PM

Answers

  • The panel PC must have two Ethernet cards.

    1. Card one is the normal card going to company network and should have the company assigned IP address.  It should also have a mask of 0.0.0.0.   If the company is using DHCP the use it.
    2. Card two is set to fixed IP address.  The 2<sup>nd</sup> card should be in be in the same subnet as the industrial device

    Industrial device 10.50.25.2 with mask 255.255.255.0

    Panel PC card 2 :  10.50.25.1 with mask 255.255.255.0

    All panel PC card two will be configured exactly the same.  The sub net should use an IP starting with 10 and not be in the same range as the company backbone IP addresses.  You should be connecting the Panel PC and industrial device using a cross over cable (not standard Ethernet cable) or through a hub.  The cross over cable at one end you should be able to see two wires crossed.  A normal Ethernet cable doesn’t have the wires crossed an either end.

    Use should use the IP address (not computer name) when connecting between Panel PC and industrial device.  Test that the connections are correct by using ping from a cmd.exe window before trying your software.  You can also test the connection using a hyper terminal application (Accessories – Communications).  Configure Hyperterminal to TCPIP and put the IP address of the industrial device and port number.  Start Industrial device before using the hyperterminal.


    jdweng

    • Marked as answer by Sygrien Friday, June 14, 2013 7:20 AM
    Thursday, June 13, 2013 9:30 PM
  • IP address starting with 10 is reserved for private networks. See following webpage

    http://en.wikipedia.org/wiki/Reserved_IP_addresses

    Here are some additional tips

    1) If yoiu change an IP address or mask of a network card you should reboot the PC for the change to take affect.

    2) Card 1 used a mask of 0.0.0.0 which is called the default gateway.  Which means that all ip addrress that aren't used selected on other network cards will go to the default gateway.  doing this will means every IP address will get routed out the PC.  YOu don't want to block any IP address from leaving the PC and if you didn't have this default gateway then some IP address wil get blocked.

    3) Card two needs a mask more restrictive than card 1 so only the only the IP addresses to your new subnet will go to card 2 and all other IP address will go out the default gateway.

    4) Here are some common masks

    255.255.255.254  - creates a subnet of 2 devices

    255.255.255.252  - creates a subnet of 4 devices

    255.255.255.248  - creates a subnet of 8 devices

    255.255.255.240  - creates a subnet of 16 devices

    255.255.255.224  - creates a subnet of 32 devices

    255.255.255.192  - creates a subnet of 64 devices

    255.255.255.128  - creates a subnet of 128 devices

    255.255.255.0      - creates a subnet of 256 devices

    255.255.254.0      - creates a subnet of 512 devices

    When you convert a mask to HEX the MSB are all ones and the LSBs are all zeroes

    255.255.255.240  is really 0xFF, 0xFF, 0xFF, 0xF0

    If your host IP address is 10.1.1.1 and mask 255.255.255.240 your subnet is 0 to 15

    If your host IP address is 10.1.1.20 and mask 255.255.255.240 your subnet is 16 to 31

    If your host IP address is 10.1.1.100 and mask 255.255.255.240 your subnet is 96 to 111

    If your host IP address is 10.1.1.101 and mask 255.255.255.240 your subnet is 96 to 111

    If your host IP address is 10.1.1.102 and mask 255.255.255.240 your subnet is 96 to 111

    4) For testing before shipping you can buy a hub and connect all the Panel PCs and industial devices to there own subnet.  Use staight ethernet cables (not cross over) to connect each device to the hub.  Give each device a different IP address.  Then you don't have to sneaker net to operate and test each system.  You can automate the testing from a central location and upload/download software and files from each device.  You can also put your office PC into the network by adding a 2nd network card to your office PC.  You can always change these IP address before shiping.

    Panel PC 1 :                  10.1.1.1 mask 255.255.255.0

    Industrial Device 1 :      10.1.1.2 mask 255.255.255.0

    Panel PC 2 :                  10.1.1.3 mask 255.255.255.0

    Industrial Device 2 :      10.1.1.4 mask 255.255.255.0

    Panel PC 3 :                  10.1.1.5 mask 255.255.255.0

    Industrial Device 3 :      10.1.1.6 mask 255.255.255.0

    Panel PC 4 :                  10.1.1.7 mask 255.255.255.0

    Industrial Device 4 :      10.1.1.8 mask 255.255.255.0


    jdweng

    • Marked as answer by Sygrien Friday, June 14, 2013 10:21 AM
    Friday, June 14, 2013 8:36 AM

All replies

  • Can you run the following command on both PCs and post results.  I will explain later

    Why I need this

    IPconfig /all > c:\temp\test.txt

    Here are some gugestions
    1) Use only one ethernet cable.  Two aren't needed except if you have an intelligent

    router or using different subnets.  See 3 below and setting up masks disucused later.

    2) Use a port numbets above 10,000 because firewall some times block port numbers

    below 1024.  Port numbers below 1024 are usually refered to a well known port numbers

    and are assigned to specific IP protocols.

    3) You may have a problem with an intelligent router.  Some intelligent routers don't

    allow more than one connection on a single ethernet cable.

     

    Question : Do I need to use two different IP addresses ? Or is it sufficient to use

    two different port numbers ? The port number on the second connection (sockets) is

    508. What port number is used to connect to SQL server ?

    Answer : A connection consists of thw follow 3 items
        A. Source IP address
        B. Destination IP address
        C. Port number

    You can have only one connection with all three items being the same.  As long as you

    are using different port number these is no issue.  The SQL server is using HTTP which

    is either port number 80 or 8080.  The SQL server can be configure to either port

    number.


    Question : Do I need to use fixed addresses ? Should I activate DHCP in one

    connection, in both ? Does it make any difference ?

    Answer : DCHP is use to resolve a PC name to an IP address. DCHP may change ip

    addresses periodically so it is better to use a computer name than IP.  I usually test

    using ping to make sure the computer name is working.  I also do this from both PC

    because sometimes a ping will work in one diection and not the other direction.  I

    first try ping using the computer name and if this doesn't work then try the IP

    address.  If the computer name doesn't work I would consult my MIS department to

    resolve the issues.  The IP mask on the interface card may be configure wrong.  See

    response below.

    Question : What are the necessary measures to make sure there will be no interaction

    from one connection to the other ?

    Answer :
         A. Firwalls/virus Protection block port numbers.
         B. Intelligent routers
         C. Netowrk cards on PC not being configured properly.
         D. Using different port numbers for each connection.

    Question : If I disconnect both cables and reconnect each of them in the other plug,

    how will the system figure out what goes where ? This puzzles me...

    Answer : Here is the full answer.

    First I will discuss the configuring of the Network cards.  Here is a typical PC

    configured with two network cards

    Card 1 : 192.11.112.1 mask 0.0.0.0        - Default Gateway allow all data
    Card 2 : 192.11.112.2 mask 255.255.255.0  - Subnet Allows only IP address 192.11.112.X

    The standard method is to configure one card as the primary gateway (company backbone

    going to internet) using a mask of 0.0.0.0.  The second card should contain a mask

    other than 0.0.0.0.  If you have more the two cards than the mask and the IP should

    not conflict.
    Card 3 : 192.11.112.3 mask 255.255.255.0 is wrong because it overlaps with card 2.
    Correct configuration
    Card 2 : 192.11.112.2   mask 255.255.255.127  - Subnet 192.11.112.0 to 127
    Card 3 : 192.11.112.129 mask 255.255.255.127  - Subnet 192.11.112.128 to 255

    IP protocol (which is impliments in the Net library and the Network card driver) is to

    use the most restictive route to send IP data.  The Card two only allows 256 IP

    address so it is more restictive than the default gateway that allow all IP addresses.

    In your case having two ethernet cables may be doing nothing or even causing a

    problem.


    Some companies don't allow hardware devices (not PCs) on the company backbone that

    don't have virus protection.  Then you a second network card in a different subnet. 

    So you would have the cards configured like this

    Card 1 : 192.11.112.1 mask 0.0.0.0        - Default Gateway allow all data
    Card 2 : 110.1.1.1 mask 255.255.255.0  - Subnet Allows only IP address 110.1.1.X

    ---------------------------------------------------------------------------------

    Now I will discuss software

    A connection has a server application one on end of the connection and a client

    application one the other end of the connection

    --------------------------------------------------------------------------------
    Server : Server Application is a listening device that is refered to as a slave device.  It processes commands and returns a response.  The SQL Server is a slave.  The Server is started

    first and listens on an Local IP address (doesn't connect to client IP) using an end Point like the software below

         string LocalHostName = Dns.GetHostName();
         IPHostEntry LocalHostIPEntry = Dns.GetHostEntry(LocalHostName);
         IPAddress LocalHostIP = LocalHostIPEntry.AddressList[0];
         LocalIPEndPointLocalTcpPort = new IPEndPoint(LocalHostIP, TcpPort);


    Note : AddressList[0] is an array.  Every IP device in the work has a loopback address

    127.0.0.1.  The loopback address and each network card is contained in this array. 

    the loopback address will get all incoming data contains on any network card.  Sending

    on the loopback adress will using the IP routing in the PC and send the data to the

    proper subnet as configured by the masks on the Network card(s).  If you use the

    endpoint of one of the cards you will only receive data coming on the one card and not

    the other network card.

    A IP device also has name called LocalHost.  Some people set LocalHost to the loopback

    address 127.0.0.1 and other set LocalHost to the IP address of the computer.  I try to

    avoid using LocalHost because it can be configured these two ways.

    The code above was choosen to listen to the Host IP name so when a client connects to the computer it will be using the computer name.

    ---------------------------------------------------------------------------------
    Client : Client application starts after the Server is in Listening Mode and connects to the server IP address.  The same one the Server is listening to.  The client is the master and sends commands to the Server and get back responses.

    ---------------------------------------------------------------------------------
    The term client has two meanings.  One at the application level and another at the socket level.  Both and Server Application and Client Application have a client socket.


    jdweng

    Thursday, June 13, 2013 2:56 AM
  • Joel,

    what an impressive answer ! Thanks a lot. I need some time to digest all this... Will be back

    Thursday, June 13, 2013 9:08 AM
  • Joel,

    I have read your message with attention and made additional tests. Since the problem occurs only when both connections are used simultaneously, I believe it is mainly a configuration issue : how to choose IP addresses and subnet masks. If you are still willing to help me, I suggest we take this on a direct personal communication. Would you like to do that ?

    Thursday, June 13, 2013 2:53 PM
  • I usually use the same addresses the are configured on the PC, or the same range that is already being used on the subnet.  If your subnet is uses DHCP then let DCHP pick the IP address.  I usually use the computer name and don't worry about the IP address.

    I believe your problem has to do with the LocalHostIPEntry.AddressList[0];.  I would 1st make surre you can ping back and forth between the two PC using the computer name.  Open up a cmd.exe window on both PC and simply type  : ping computer_name, where computer name is the other PC name.  If this works your ethernet connection are good.  Use only one eithernet cable.  If this doesn't work then let me see the reults of the ipconfig /all.

    Once the pin works  Start the application up.  On the client PC run a Hyperterminal ( Accessories - Communications).   Set it up of TCPIP and enter the server name and por tnumber you are using.  the hyperterminal should connect.  You can even type characters on the hyperterminal and your server application should be able to read these character.  If the server responds you can see the responses on the hyperterminal.


    jdweng

    Thursday, June 13, 2013 5:11 PM
  • Thanks again Joel,

    This is the context :

    The application runs on a Panel PC (a touch-computer with no keyboard), connected to an industrial device.

    The panel PC has two RJ45 plugs.

    The industrial device has one RJ45 plug.

    Also, the Panel PC needs to connect to a database, located on a server.

    So I have 3 types of equipment :

    • The server, on which I have no control. Its IP address and subnet mask are fixed.
    • The Panel PC, over which I have full control.
    • The industrial device, which contains a web server, so it is configurable.

    A typical installation contains :

    • Only one server
    • Several panel PCS
    • Several industrial devices. There is always as  many Panel PCs as industrial devices. An industrial device is always connected to only one Panel PC. So there are several “equipment pairs”, each including one Panel PC and one industrial device.

    The constraints are :

    1. Each panel PC must see a shared directory on the server. I have observed that this is possible when the panel PC has a fixed IP address.
    2. Each panel PC must communicate with the server database through the company network.
    3. Each panel PC must communicate with its own industrial device (a panel PC has two RJ45 plugs). In fact, only the Panel PC should communicate with the industrial device.
    4. All industrial devices are shipped with the same default IP address and mask. If possible, I would like to keep the default address. Therefore, I’m thinking of making “private” the network between an industrial device and its related panel PC. What I mean by “private” is that several industrial devices will have the same IP address and mask. Is it possible ?

    How may I achieve this ?

    Thursday, June 13, 2013 7:47 PM
  • The panel PC must have two Ethernet cards.

    1. Card one is the normal card going to company network and should have the company assigned IP address.  It should also have a mask of 0.0.0.0.   If the company is using DHCP the use it.
    2. Card two is set to fixed IP address.  The 2<sup>nd</sup> card should be in be in the same subnet as the industrial device

    Industrial device 10.50.25.2 with mask 255.255.255.0

    Panel PC card 2 :  10.50.25.1 with mask 255.255.255.0

    All panel PC card two will be configured exactly the same.  The sub net should use an IP starting with 10 and not be in the same range as the company backbone IP addresses.  You should be connecting the Panel PC and industrial device using a cross over cable (not standard Ethernet cable) or through a hub.  The cross over cable at one end you should be able to see two wires crossed.  A normal Ethernet cable doesn’t have the wires crossed an either end.

    Use should use the IP address (not computer name) when connecting between Panel PC and industrial device.  Test that the connections are correct by using ping from a cmd.exe window before trying your software.  You can also test the connection using a hyper terminal application (Accessories – Communications).  Configure Hyperterminal to TCPIP and put the IP address of the industrial device and port number.  Start Industrial device before using the hyperterminal.


    jdweng

    • Marked as answer by Sygrien Friday, June 14, 2013 7:20 AM
    Thursday, June 13, 2013 9:30 PM
  • Thanks Joel.

    What is the meaning of an IP address starting with 10 ?

    Friday, June 14, 2013 7:20 AM
  • IP address starting with 10 is reserved for private networks. See following webpage

    http://en.wikipedia.org/wiki/Reserved_IP_addresses

    Here are some additional tips

    1) If yoiu change an IP address or mask of a network card you should reboot the PC for the change to take affect.

    2) Card 1 used a mask of 0.0.0.0 which is called the default gateway.  Which means that all ip addrress that aren't used selected on other network cards will go to the default gateway.  doing this will means every IP address will get routed out the PC.  YOu don't want to block any IP address from leaving the PC and if you didn't have this default gateway then some IP address wil get blocked.

    3) Card two needs a mask more restrictive than card 1 so only the only the IP addresses to your new subnet will go to card 2 and all other IP address will go out the default gateway.

    4) Here are some common masks

    255.255.255.254  - creates a subnet of 2 devices

    255.255.255.252  - creates a subnet of 4 devices

    255.255.255.248  - creates a subnet of 8 devices

    255.255.255.240  - creates a subnet of 16 devices

    255.255.255.224  - creates a subnet of 32 devices

    255.255.255.192  - creates a subnet of 64 devices

    255.255.255.128  - creates a subnet of 128 devices

    255.255.255.0      - creates a subnet of 256 devices

    255.255.254.0      - creates a subnet of 512 devices

    When you convert a mask to HEX the MSB are all ones and the LSBs are all zeroes

    255.255.255.240  is really 0xFF, 0xFF, 0xFF, 0xF0

    If your host IP address is 10.1.1.1 and mask 255.255.255.240 your subnet is 0 to 15

    If your host IP address is 10.1.1.20 and mask 255.255.255.240 your subnet is 16 to 31

    If your host IP address is 10.1.1.100 and mask 255.255.255.240 your subnet is 96 to 111

    If your host IP address is 10.1.1.101 and mask 255.255.255.240 your subnet is 96 to 111

    If your host IP address is 10.1.1.102 and mask 255.255.255.240 your subnet is 96 to 111

    4) For testing before shipping you can buy a hub and connect all the Panel PCs and industial devices to there own subnet.  Use staight ethernet cables (not cross over) to connect each device to the hub.  Give each device a different IP address.  Then you don't have to sneaker net to operate and test each system.  You can automate the testing from a central location and upload/download software and files from each device.  You can also put your office PC into the network by adding a 2nd network card to your office PC.  You can always change these IP address before shiping.

    Panel PC 1 :                  10.1.1.1 mask 255.255.255.0

    Industrial Device 1 :      10.1.1.2 mask 255.255.255.0

    Panel PC 2 :                  10.1.1.3 mask 255.255.255.0

    Industrial Device 2 :      10.1.1.4 mask 255.255.255.0

    Panel PC 3 :                  10.1.1.5 mask 255.255.255.0

    Industrial Device 3 :      10.1.1.6 mask 255.255.255.0

    Panel PC 4 :                  10.1.1.7 mask 255.255.255.0

    Industrial Device 4 :      10.1.1.8 mask 255.255.255.0


    jdweng

    • Marked as answer by Sygrien Friday, June 14, 2013 10:21 AM
    Friday, June 14, 2013 8:36 AM
  • Great, thanks again Joel !
    Friday, June 14, 2013 10:21 AM