Rabbit TCP client

Hello, I would like etablish a connection between a server on my VM and my card. Currently, I have a connection between my VM and my card (BL4S100) but only with my VM as client and my card as server. I have a server on my VM but my problem is to establish this connection considering my card as a client and not a server. I’m looking for somes example if you have or the beginning to move forward on my project. At the moment I have try this :


 void main()
{

	static tcp_Socket my_socket;
	longword host;
	tcp_Socket tsock;
   struct sockaddr_in server_addr;
   struct hostent *server;

   char buffer[256];


   ifconfig(IF_DEFAULT, IFS_IPADDR, aton("10.10.16.108"),
	IFS_NETMASK, aton("255.255.255.0"),
	IFS_ROUTER_SET, aton("10.10.16.253"),
	IFS_UP,
	IFS_END);

   // création de la socket


  		sock_init();
     		 while (ifpending(IF_DEFAULT) == IF_COMING_UP)
      		{
			  		tcp_tick(NULL);
				}	//_or_exit(1);

            // server = gethostbyname(argv[1]);

 			  if (!(host = resolve(ADDRESS)))
   			{
					puts("Could not resolve host");
					exit(3);
	  			}
		port = atoi( PORT );
		printf("Attempting to open '%s' on port %u
\r", ADDRESS,
		port );
    if ( !tcp_open( &tsock, 0, host, port , NULL ) > 0) {
	puts("Unable to open TCP session");
	exit(3);
	}
	printf("Waiting a maximum of %u seconds for connection to be established
\r", sock_delay );
	while (!sock_established(&tsock) &&
		sock_bytesready(&tsock)== -1){
		tcp_tick(NULL);
		}
	puts("Socket is established");
	sock_close( &tsock );
	exit(0);

}

I don’t know/understand how to define the parameters to connect directly my card at my server.

Thank you for your help !

Your tcp_open() call looks good. “Samples cpip\active.c” demonstrates usage of that call, and could be another sample to test to verify connectivity.

So what’s happening when you try your program? Is it able to connect? Do you have another device/computer you can place on that Ethernet connection to verify that the host and/or a firewall aren’t blocking inbound connections on your VM?

If you can run a web server on your VM, you could try using the “http client.c” sample to connect to it.

Using the POP3, FTP, SMTP or HTTP client libraries might be a place you could look for code that connects to a server and uses a state machine to interact with it.

1 Like

Thank you it works.