How to invoke gst via udp communication

I want to call gst to push and pull stream through udp server and client. When the push stream module is encapsulated into a function, the gst wrapper function is called in the main program by determining the client instructions to push the stream, but I find that it cannot be entered into the gst wrapper function. Does the gst module have to be used alone or in the main program? Here’s the call part of my main program:

if(strcmp(cleaned_buf, "udpClient test1") == 0 )
                {
                    printf("===udpClient test1===\n");
                    instruction_switch(1);
                }

gst function code is as follows:

int instruction_switch(int instNum)
{
  g_print ("into instruction_switch\n");
  GMainLoop *loop;
  GstRTSPServer *server;
  GstRTSPMountPoints *mounts;
  GstRTSPMediaFactory *factory;
  GOptionContext *optctx;
  GError *error = NULL;
  gchar *ip_address = "192.168.3.80"; 
  gchar *port = "8554"; 
  loop = g_main_loop_new (NULL, FALSE);
  server = gst_rtsp_server_new ();
  g_object_set(server, "service", port, "address", ip_address, NULL);
  mounts = gst_rtsp_server_get_mount_points (server);
  factory = gst_rtsp_media_factory_new ();
  char *instruction1 = "(compositor name=mix sink_0::alpha=1 sink_0::xpos=0 sink_0::ypos=0 sink_0::width=640 sink_0::height=480 sink_1::alpha=1 sink_1::xpos=0 sink_1::ypos=165 sink_1::width=180 sink_1::height=150 sink_2::alpha=1 sink_2::xpos=460 sink_2::ypos=165 sink_2::width=180 sink_2::height=150 ! videoconvert ! mpph264enc bps-max=1000 ! h264parse ! rtph264pay name=pay0 pt=96 v4l2src device=/dev/video11 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480,pixel-aspect-ratio=1/1 ! mix.sink_0 v4l2src device=/dev/video12 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480,pixel-aspect-ratio=1/1 ! videoflip video-direction=180 ! mix.sink_1 v4l2src device=/dev/video13 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480,pixel-aspect-ratio=1/1 ! mix.sink_2 )";
if(instNum == 1){
    g_print ("instNum is 1\n");
    gst_rtsp_media_factory_set_launch (factory, instruction1);
  }
  gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
  g_object_unref (mounts);
  gst_rtsp_server_attach (server, NULL);
  g_main_loop_run (loop);
  return 0;
}

Forgot to use gst_init to initialize