title: SDL_net UDP Packet data
body: <p>I'm new to network programming. I've done a little bit with TCP sockets, and I'm trying my had at a simple UDP client(s)/server. </p>
  
  <p>I'm using the SDL_net framework for this project. </p>
  
  <p>The issue I'm running into is the UDPpacket struct uses <code>Uint8 *</code> as the data type for the data. I just want to be able to send straight up text, however. I've read a bit on casting, but nothing seems to be compatible, and I'm struggling to find the correct solution to this. </p>
  
  <p>The code to the client is shown below. The error, as you would assume,is when I try and set p-data (towards the bottom of the code). </p>
  
  <p>Any advice or corrections you have would be greatly appreciated!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;SDL2/SDL.h&gt;
  #include &lt;SDL2_net/SDL_net.h&gt;
  
  using namespace std;
  
  
  int main(int argc, const char * argv[]) {
  
      UDPsocket sd;
  
      //create the socket
      if(!(sd = SDLNet_UDP_Open(0))) {
          printf("Could not create socket\n");
          SDLNet_Quit();
          SDL_Quit();
          exit(1);
      }
  
      //get my address
      IPaddress* myaddress = SDLNet_UDP_GetPeerAddress(sd, -1);
      if(!myaddress) {
          printf("Could not get own port\n");
          exit(2);
      }
  
      cout &lt;&lt; "My Port: " &lt;&lt; myaddress-&gt;port &lt;&lt; endl;
  
  
      /******************************
      * These are used to recieve
      *******************************/
  
      UDPpacket * rcvP = SDLNet_AllocPacket(1024);
      if(!rcvP) {
          printf("Could not allocate receiving packet\n");
          exit(3);
      }
  
      UDPsocket rcvS;
      rcvS = SDLNet_UDP_Open(myaddress-&gt;port);
      if(!rcvS)
      {
          printf("Could not allocate receiving socket\n");
          exit(4);
      }
  
      //resolve the address of the server
      IPaddress srvHost;
      IPaddress * ip = &amp; srvHost;
      SDLNet_ResolveHost(ip, "localhost", 8888);
  
      //set up the packet
      UDPpacket * p = SDLNet_AllocPacket(1024);
      if(!p) {
          printf("Could not allocate packet\n");
          SDLNet_Quit();
          SDL_Quit();
          exit(2);
      }
  
      //link the server address to our packet
      p-&gt;address.host = srvHost.host;
      p-&gt;address.port = srvHost.port;
  
  
      //main loop
      while(true){
  
          SDL_Event e;
          while(SDL_PollEvent(&amp;e))
          {
              if(e.type == SDL_KEYDOWN)
              {
                  char * data;
                  switch(e.key.keysym.sym)
                  {
                      case SDLK_LEFT:
                          p-&gt;data = "left";
                          p-&gt;len  = strlen("left") + 1;
                          SDLNet_UDP_Send(sd, -1, p);
                          break;
                      case SDLK_RIGHT:
                          p-&gt;data = "right";
                          p-&gt;len  = strlen("right") + 1;
                          SDLNet_UDP_Send(sd, -1, p);
                          break;
                      default:
                          break;
                  }
              }
          }
  
      }
  
          return 0;
  }
  </code></pre>