I'm trying to achieve TCP connection over sockets on my stm32 F4 discovery board with a computer, but my program stops at connect() function after creating socket.
It's possible to connect to the board via telnet. Ping command works, and a server responds on every packet. I have server application listening on the same port on the computer. The same "client" application works well on Linux.
I'm using ENC28J60 chip as a Ethernet driver.
When I'm using telnet I can see in wireshark that the board is responding, however when I try to connect via socket, there are no messages from board.
I have no clue what's going on... The application is really simple. Maybe somebody has experience with using sockets on NuttX and can help me.
My configuration includes:
CONFIG_NET_TCP=y
CONFIG_NET_TCP_CONNS=40
CONFIG_NET_MAX_LISTENPORTS=40
CONFIG_NET_TCP_RECVDELAY=0
CONFIG_NET_UDP=y
CONFIG_NET_ICMP=y
CONFIG_NSOCKET_DESCRIPTORS=10
CONFIG_NET_NACTIVESOCKETS=16
CONFIG_NET_SOCKOPTS=y
CONFIG_NET_PKT=y
CONFIG_NET_PKT_CONNS=1
CONFIG_SCHED_WORKQUEUE=y
# CONFIG_SCHED_HPWORK is not set <--- Also tested on High priority queue
CONFIG_SCHED_LPWORK=y
# CONFIG_DISABLE_POLL is not set
CONFIG_NET_IPv4=y
CONFIG_NET=y
CONFIG_NSH_TELNET=y
CONFIG_NETUTILS_PING=y
CONFIG_SYSTEM_PING=y
CONFIG_NSH_IPADDR=0xc0a801c8
CONFIG_NSH_DRIPADDR=0xc0a80101
CONFIG_NSH_NETMASK=0xffffff00
CONFIG_NSH_NOMAC=y
CONFIG_NSH_SWMAC=y
CONFIG_NSH_MACADDR=0x00e0deadbeef
CONFIG_NSH_NETINIT=y
Application code:
#include <nuttx/config.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#ifdef CONFIG_BUILD_KERNEL
int main(int argc, FAR char *argv[])
#else
int tcpconnect_main(int argc, char *argv[])
#endif
{
int sockfd;
struct sockaddr_in server;
server.sin_addr.s_addr = inet_addr("192.168.1.3"); // IP ADRESS!
server.sin_family = AF_INET;
server.sin_port = htons(502); // PORT!
printf("Creating socket...\n");
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
{
printf("Could not create socket.\n");
}
printf("Socket created!\n");
printf("Connecting with server...\n");
if (connect(sockfd , (struct sockaddr *)&server , sizeof(server)) < 0)
{
printf("Connect failed. Error.\n");
return 1;
}
printf("Connected!\n");
printf("Sending message...\n");
if(send(sockfd, "Test\n", 5, 0) < 0)
{
printf("Send failed.");
return 1;
}
printf("Sended!\n");
close(sockfd);
return 0;
}
Configuration and application code in attachment.
Best regards,
Robert