Home/Support/Support Forum/Rabbit TCP client
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Rabbit TCP client

0 votes
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(""), IFS_NETMASK, aton(""), IFS_ROUTER_SET, aton(""), 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\n\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\n\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 !
asked Aug 24, 2020 in Rabbit by JPal New to the Community (7 points)

Please log in or register to answer this question.

1 Answer

+1 vote
Best answer
Your tcp_open() call looks good. "Samples\tcpip\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.
answered Aug 27, 2020 by TomCollins Veteran of the Digi Community (2,085 points)
selected Sep 2, 2020 by TomCollins
Thank you it works.