Cannot connect two services using raw TCP socket

Hi, I’m currently new to Istio and I’m using it to setup a small TCP socket client-server with 1 server (2 deployments) and 1 client (1 deployment). However, I cannot seem to get the requests forwarded, there are simply no routes whatsoever, the logs on the client side still gives a connection failed alert. The socket codes, deployments, virtualservice and my destination rule are posted in the comment section (I’m limited to post a long topic as a new user).

I’ve been solving this problem for quite a long time, so I’m very thankful if someone can help me.

Socket code:

client file:
#define PORT 8080

int main(int argc, char const *argv[]) 
{ 
	int sock = 0, valread; 
	struct sockaddr_in serv_addr; 
	char *hello = "Hello from client"; 
	char buffer[1024] = {0}; 
	if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
	{ 
		printf("\n Socket creation error \n"); 
		return -1; 
	} 

	serv_addr.sin_family = AF_INET; 
	serv_addr.sin_port = htons(PORT); 
	
	// Convert IPv4 and IPv6 addresses from text to binary form 
	if(inet_pton(AF_INET, "0.0.0.0", &serv_addr.sin_addr)<=0) 
	{ 
		printf("\nInvalid address/ Address not supported \n"); 
		return -1; 
	} 

	while (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) 
	{ 
		printf("\nConnection Failed. Reconnecting ... \n"); 
		sleep(2);
		 
	}
	while(1){
		send(sock , hello , strlen(hello) , 0 ); 
		printf("Hello message sent\n"); 
		sleep(1);
	}
	
	return 0; 
} 

server file:

#define PORT 8080
int main(int argc, char const *argv)
{
int server_fd, new_socket, valread;
struct sockaddr_in address;
int opt = 1;
int addrlen = sizeof(address);
char buffer[1024] = {0};
char *hello = “Hello from server”;

// Creating socket file descriptor
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
{
perror(“socket failed”);
exit(EXIT_FAILURE);
}

// Forcefully attaching socket to the port 8080
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT,
&opt, sizeof(opt)))
{
perror(“setsockopt”);
exit(EXIT_FAILURE);
}
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons( PORT );

// Forcefully attaching socket to the port 8080
if (bind(server_fd, (struct sockaddr *)&address,
sizeof(address))<0)
{
perror(“bind failed”);
exit(EXIT_FAILURE);
}
if (listen(server_fd, 3) < 0)
{
perror(“listen”);
exit(EXIT_FAILURE);
}
if ((new_socket = accept(server_fd, (struct sockaddr )&address,
(socklen_t
)&addrlen))<0)
{
perror(“accept”);
exit(EXIT_FAILURE);
}
while(1){
valread = read( new_socket , buffer, 1024);
printf("%s\n",buffer );
sleep(1);
}

return 0;
}

Deployment file:

---
apiVersion: v1
kind: Service
metadata: 
  labels: 
    app: sp-server
    service: sp-server
  name: sp-server
spec:
#   # type: NodePort
  ports: 
  - port: 8080
#     # targetPort: 80
#     # nodePort: 32160
    protocol: TCP
    name: http
  selector: 
    app: sp-server
---
apiVersion: apps/v1
kind: Deployment
metadata: 
  labels: 
    app: sp-server
    version: v1
  name: sp-server-v1
spec: 
  replicas: 1
  selector: 
    matchLabels: 
      app: sp-server
      version: v1
  template: 
    metadata: 
      labels: 
        app: sp-server
        version: v1
    spec: 
      containers:     
      - name: sp-server
        image: kienkauko/socket:server2.0
        ports: 
        - containerPort: 8080
      nodeSelector:
        kubernetes.io/hostname: node5
---
apiVersion: apps/v1
kind: Deployment
metadata: 
  labels: 
    app: sp-server
    version: v2
  name: sp-server-v2
spec: 
  replicas: 1
  selector: 
    matchLabels: 
      app: sp-server
      version: v2
  template: 
    metadata: 
      labels: 
        app: sp-server
        version: v2
    spec: 
      containers:     
      - name: sp-server
        image: kienkauko/socket:server2.0
        ports: 
        - containerPort: 8080
      nodeSelector:
        kubernetes.io/hostname: node6
---

apiVersion: v1
kind: Service
metadata: 
  labels: 
    app: sp-client
    service: sp-client
  name: sp-client
spec:
  # type: NodePort
  ports: 
  - port: 8080
    # targetPort: 80
    # nodePort: 32161
    protocol: TCP
    name: http
  selector: 
    app: sp-client
---
apiVersion: apps/v1
kind: Deployment
metadata: 
  labels: 
    app: sp-client
    version: v1
  name: sp-client-v1
spec: 
  replicas: 1
  selector: 
    matchLabels: 
      app: sp-client
      version: v1
  template: 
    metadata: 
      labels: 
        app: sp-client
        version: v1
    spec: 
      containers:     
      - name: sp-client
        image: kienkauko/socket:client0.0
        ports: 
        - containerPort: 8080
      nodeSelector:
        kubernetes.io/hostname: node6          

Virtual-service file:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: socket-route
spec:
hosts:
- sp-server
http:
- route:
- destination:
host: sp-server
port:
number: 8080
subset: v1
weight: 35
# websocketUpgrade: true
- destination:
host: sp-server
port:
number: 8080
subset: v2
weight: 65
# websocketUpgrade: true

Destination-rule file:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: socket-route
spec:
  hosts: 
  - sp-server
  http:
  - route:
    - destination:
        host: sp-server
        port:
          number: 8080 
        subset: v1
      weight: 35
      # websocketUpgrade: true
    - destination:
        host: sp-server
        port:
          number: 8080
        subset: v2
      weight: 65
      # websocketUpgrade: true

Here is the problem: