Keil Logo

TCP Server is not working!

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Author
Mujtaba Hossaini
Posted
7-Jan-2018 06:23 GMT
Toolset
ARM
New! TCP Server is not working!

Dear Friends,
I am trying to create a simple TCP server using STM32F107RCt6 microcontroller and DP83848C PHY. I use CMSIS RTXv4 and Keil uVision5 pro and Keil Network component version 7.7.0.
In RTX_Conf_CM.c configuration wizard, I've done the following configuration:
Default Thread Stack size: 512
Main Thread Stack size: 800
Number of Threads with user-provided stack size: 2(netETH_Thread and netCore_Thread)
Total stack size for user-provided stack size: 1536(512+1024)
and user timers are enable.
The Stack size and Heap size are respectively 1024 and 512 bytes.
In RTE.h file I've enabled Ethernet RMII mode. The AHB clock and system clock are 72MHz.
I've added the TCP_Socket_Server.c template file and uncomment lines 18 and 42 and delete IPv6 code and change the client IP address to my computer IP.
The code is as follows:


#include "rl_net.h"

// Notify the user application about TCP socket events.
uint32_t tcp_cb_server (int32_t socket, netTCP_Event event,
                        const NET_ADDR *addr, const uint8_t *buf, uint32_t len) {

  switch (event) {
    case netTCP_EventConnect:
      // Connect request received
      if (addr->addr_type == NET_ADDR_IP4) {
        // IPv4 client
        if (addr->addr[0] == 192  &&
            addr->addr[1] == 168  &&
            addr->addr[2] == 0    &&
            addr->addr[3] == 101) {
          // Accept connection from client at 192.168.0.101
          return (1);
        }
      }
      // Deny connection.
      return (0);
    case netTCP_EventEstablished:
      // Connection established
      break;

    case netTCP_EventClosed:
      // Connection was properly closed
      break;

    case netTCP_EventAborted:
      // Connection is for some reason aborted
      break;

    case netTCP_EventACK:
      // Previously sent data acknowledged
      break;

    case netTCP_EventData:
      // Data received
      /* Example
      if ((buf[0] == 0x01) && (len == 2)) {
        // Switch LEDs on and off
        // LED_out (buf[1]);
      }
      */
      break;
  }
  return (0);
}

// Allocate and initialize the socket.
int main (void) {
  int32_t tcp_sock;
  netInitialize ();
  // Initialize TCP Socket and start listening on port 2000
  tcp_sock = netTCP_GetSocket (tcp_cb_server);
  if (tcp_sock > 0) {
    netTCP_Listen (tcp_sock, 2000);
  }
}
//! [code_TCP_Socket_Server]


Unfortunately, the code is not working and I have no idea how to solve it.
Any helps would be greatly appreciated.

Author
Tamir Michael
Posted
7-Jan-2018 09:19 GMT
Toolset
ARM
New! RE: TCP Server is not working!

Your program is terminated - you need to add an infinite loop to your main and poll the networking library.

Author
Mujtaba Hossaini
Posted
7-Jan-2018 10:27 GMT
Toolset
ARM
New! RE: TCP Server is not working!

Dear Tamir Michael,

Thank you for your reply.

Could you please tell me what you mean by saying poll the networking library in your infinite loop in main? Is there any especial function that I should call?

Author
Tamir Michael
Posted
7-Jan-2018 17:01 GMT
Toolset
ARM
New! RE: TCP Server is not working!

You mentioned you were using RTX but the code excerpt you provided show no evidence of that. Still, that does not essentially change the situation - your program must include an infinite loop

int main()
{
    while (1)
    {
        // look at the TCP library's documentation and examples; There must be a function to call regularly to make sure it services its buffers and queue and generally works at all
        ...
    }
}
Author
Tamir Michael
Posted
7-Jan-2018 17:04 GMT
Toolset
ARM
New! RE: TCP Server is not working!

http://www.keil.com/appnotes/files/apnt_268.pdf

Author
Danish Shaikh
Posted
9-Apr-2018 16:08 GMT
Toolset
ARM
New! RE: TCP Server is not working!

Dear Mujtaba Hossaini,

I am also facing the same issue. Is you have resolved the issue? Please reply asap.

Thanks in advance.

Author
Andrew Neil
Posted
9-Apr-2018 19:57 GMT
Toolset
ARM
New! RE: I am also facing the same issue

Then you should also follow the same advice that Tamir Michael has already posted.

In particular, did you read the App Note ?

Author
Bikas Gaur
Posted
12-Apr-2018 13:30 GMT
Toolset
ARM
New! RE: I am also facing the same issue

Is there any plan for ARM to release a mobile client for Keil?

Author
Danish Shaikh
Posted
16-Apr-2018 18:50 GMT
Toolset
ARM
New! RE: I am also facing the same issue

thanks for the reply.

The app note is not relevant to my query.
I have followed the suggestion given in earlier post but thats not resolved the problem

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.