Search code examples
c#network-programmingtcptcpclienttcplistener

Is it possible to set arbitrary ip address to tcpClient?


I got a diagnostic program to work with network of hardware equipment. Interconnection is based on TCP protocol. Diagnostic program is server and uses TcpListener to listen for connections, hardware acts as client which connects to server and transmit data. Ip addresses of diagnostic program and hardware equipment are predefined and must be unchanged, diagnostic program await only predefined hardware ip addresses.
Ip address of diagnostic program is 192.168.1.11, hardware equipment's - 192.168.1.200, 192.168.1.201, etc.

+--------------+     +---------------+  
| [server]     |<--->| [hw client1]  |  
|              |     | 192.168.1.200 |  
| diagnostic   |     +---------------+  
| program      |     +---------------+  
| 192.168.1.11 |<--->| [hw client2]  |  
+--------------+     | 192.168.1.201 |  
                     +---------------+  

Hardware currently implements part of internal protocol and diagnostic program works fine. I want to improve diagnostic program and implement next part of internal protocol without hardware equipment (its software not ready). To do this I want to implement software emulator to work as hardware. My plan is to create tcpClient, which implements internal protocol used in interaction between diagnostic program and hardware equipment.
The problem is that I cannot set arbitrary ip address to tcpClient. I can only work through localhost.
Is it possible to create program which will implement tcpClient with desired ip address (for example 192.168.1.200)?


Solution

  • I got another approach.
    I wanted solution which will not impact my diagnostic program in any way.
    I used virtual machine (by means of virtualbox). Main problem was to properly set up ip addresses of host and vitrual machine. Host machine is 192.168.1.11, inside virtual machine - 192.168.1.200.
    As a result, diagnostic program is unchanged, client runs at virtual machine.