- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have multiple threads of the function below and can only connect to 1 port at a time. I'm testing this code by running Hyperterminal on a PC and simply connecting and disconnecting the port. Each port works, each thread works, but I must close the open port on Hyperterminal before I can connect to the other port and verse visa. I've read about a bunch of other ways to support multiple ports, using select( ) and scanning through a list of sockets, but I'd like to get this to work.
Not sure if I have something configured improperly with MQX or RTCS or I'm just doing something silly with my code. This same approach worked with Nucleus OS.
Again, not trying to get advice on how to do it differently unless what I'm trying ain't gonna work, just trying to figure out why this approach isn't working.
Any help appreciated....
Thank You
void tcp_task (uint32 channel)
{
char str[80];
int err;
uint32 option;
uint32 count;
sockaddr addr;
uint32 listen_sock;
uint32 client_sock;
rtcs_fd_set rfds;
CHANNEL_PTR p = com_ptrs[channel];
/* Prepare socket for incoming connections */
listen_sock = socket(PF_INET, SOCK_STREAM, 4);
option = SERIAL_SOCKET_BUFFER_SIZE;
(void) setsockopt(listen_sock, SOL_TCP, OPT_TBSIZE, &option, sizeof(option));
(void) setsockopt(listen_sock, SOL_TCP, OPT_RBSIZE, &option, sizeof(option));
((sockaddr_in*) &addr)->sin_family = AF_INET;
((sockaddr_in*) &addr)->sin_port = ports[channel-TCP1];
((sockaddr_in*) &addr)->sin_addr.s_addr = INADDR_ANY;
bind(listen_sock, &addr, sizeof(addr));
listen(listen_sock, 0);
RTCS_FD_ZERO(&rfds);
RTCS_FD_SET(listen_sock,&rfds);
while(1) {
_time_delay_ticks(1);
/* Accept incoming connection */
client_sock = accept(listen_sock, NULL, NULL);
if(client_sock == RTCS_SOCKET_ERROR)
continue;
/* Set socket option OPT_RECEIVE_NOWAIT = TRUE */
option = TRUE;
setsockopt(client_sock, SOL_TCP, OPT_RECEIVE_NOWAIT, &option, sizeof(option));
status[channel] = CONNECTED;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So after another 6 hours of debugging, it turns out the code does works and the problem is with Hyperterminal. I'm running W10 with W7 Hyperterminal and not seeing an attempt to connect to a second port while another port is open.
Too bad I trusted Windows and assumed it was a code problem on my side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So after another 6 hours of debugging, it turns out the code does works and the problem is with Hyperterminal. I'm running W10 with W7 Hyperterminal and not seeing an attempt to connect to a second port while another port is open.
Too bad I trusted Windows and assumed it was a code problem on my side.
