• AVR Freaks

Create an Client/Server project with PIC32

Page: < 12 Showing page 2 of 2
Author
NKurzman
A Guy on the Net
  • Total Posts : 18060
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: Create an Client/Server project with PIC32 2018/09/25 19:20:12 (permalink)
5 (1)
Start with the unaltered App.
connect it to your Wired? Network? ( Ethernet Starter Kit?)
If you have Wireshark see if it is getting an IP Address from your DHCP Server.
which I assume you have.  As Pointed ot this means the default one will not work.
Run C:\microchip\harmony\v2_06_00\utilities\tcpip_discoverer.
It will find your Board and tell you its IP Address.
The MAC Address should Stare with D8:80
 
This works, the Software is not Broken.  There is an issue with your Setup.
 
 
#21
KokuH
Starting Member
  • Total Posts : 45
  • Reward points : 0
  • Joined: 2018/05/07 08:45:14
  • Location: France
  • Status: offline
Re: Create an Client/Server project with PIC32 2018/09/27 07:17:19 (permalink)
0
Hello,
So ! after trying your idea, I launched tcpip_discoverer and I saw that it receives nothing on his console so I visualized with the wireshark, and I saw that the tcpip_discoverer sending a broadcast address but the ESK does not answer! so I deduced that it does not work!

So, I ordered an ESK II, and I received it today, I tried all the demos, and she walk all!
 
I launched tcpip_discoverer and received the MAC address, IP, hostname of ESK II (192.168.1.23)
 
Now I'm focusing on the berkeley_tcp_server demo, to build a client / server.

I created a client program with python on an RPI and it allows to send "Hello" to the server (ESK II), it answers the same thing ("Hello"), in fact, the code of this demo is to receive something and send to the client what's in the buffer!
 
I would like to send a data frame (bytes) for example ([0x7E, 0x18, 0x01, ...]) from the ESK II to the RPI so send a server data frame (ESK II) to the client ( RPI).
 
I tried to modify the code but I always receive errors, you will have indications?
 
Here is the server code of the demo:
 
            // Create a socket for this server to listen and accept connections on
            SOCKET tcpSkt = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
            if (tcpSkt == INVALID_SOCKET)
                return;
            appData.bsdServerSocket = (SOCKET) tcpSkt;

            appData.state = APP_BSD_BIND;
        }
            break;

        case APP_BSD_BIND:
        {
            // Bind socket to a local port
            struct sockaddr_in addr;
            int addrlen = sizeof (struct sockaddr_in);
            addr.sin_port = SERVER_PORT;
            addr.sin_addr.S_un.S_addr = IP_ADDR_ANY;
            if (bind(appData.bsdServerSocket, (struct sockaddr*) &addr, addrlen) == SOCKET_ERROR)
                return;

            appData.state = APP_BSD_LISTEN;
            // No break needed
        }
            break;

        case APP_BSD_LISTEN:
        {
            if (listen(appData.bsdServerSocket, MAX_CLIENT) == 0) {
                appData.state = APP_BSD_OPERATION;
                SYS_CONSOLE_PRINT("Waiting for Client Connection on port: %d\r\n", SERVER_PORT);
            }
        }
            break;
        case APP_BSD_OPERATION:
        {
            int length;
            struct sockaddr_in addRemote;
            int addrlen = sizeof (struct sockaddr_in);
            char buffer[15];
            

            for (i = 0; i < MAX_CLIENT; i++) {
                // Accept any pending connection requests, assuming we have a place to store the socket descriptor
                if (appData.ClientSock[i] == INVALID_SOCKET)
                    appData.ClientSock[i] = accept(appData.bsdServerSocket, (struct sockaddr*) &addRemote, &addrlen);

                // If this socket is not connected then no need to process anything
                if (appData.ClientSock[i] == INVALID_SOCKET)
                    continue;

                // For all connected sockets, receive and send back the data
                length = recv(appData.ClientSock[i], buffer, sizeof (buffer), 0);

                if (length > 0) {
                    buffer[length] = '\0';
                    send(appData.ClientSock[i], buffer, strlen(buffer), 0);
                }
                // else just wait for some more data
            }
        }
            break;
        default:
            break;
    }
}

 
#22
KokuH
Starting Member
  • Total Posts : 45
  • Reward points : 0
  • Joined: 2018/05/07 08:45:14
  • Location: France
  • Status: offline
Re: Create an Client/Server project with PIC32 2018/10/02 06:36:17 (permalink)
0
Hello [<font][<font][<font][<font]NKurzman
 
[<font][<font][<font][<font]After buying the ESK II, I was able to continue my progress with MPLAB Harmony, but I find myself in a configuration problem! I posted another topic to have more answers, here is the subject that I posted (https://www.microchip.com/forums/FindPost/1069952), if you could give me some indications, it would be great!
 
[<font][<font][<font][<font]Thank you for everything
#23
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5