2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24 #include <sys/socket.h>
27 #include <vcl/vppcom.h>
28 #include <vcl/vcl_event.h>
31 char MESSAGE[] = "Hello, World!\n";
33 static const int PORT = 9995;
36 listener_cb (uint32_t new_session_index, vppcom_endpt_t *ep, void *stuff)
39 vppcom_session_write (new_session_index, &MESSAGE, sizeof (MESSAGE));
40 printf ("\n Heard from port: %d\n", ep->port);
44 typedef struct vppcomm_listener_main_
50 } vppcomm_listener_main_t;
52 vppcomm_listener_main_t _vlm_main;
53 vppcomm_listener_main_t *vlm = &_vlm_main;
57 main (int argc, char **argv)
61 struct sockaddr_in sin;
65 clib_mem_init_thread_safe (0, 64<<20);
68 memset (&sin, 0, sizeof (sin));
69 sin.sin_family = AF_INET;
70 sin.sin_port = htons (PORT);
71 //sin.sin_addr.s_addr = inet_addr("127.0.0.1");
73 endpt.is_ip4 = (sin.sin_family == AF_INET);
74 endpt.ip = (uint8_t *) & sin.sin_addr;
75 endpt.port = (uint16_t) sin.sin_port;
78 rv = vppcom_app_create ("test_vcl_listener_server");
81 listen_fd = vppcom_session_create (VPPCOM_PROTO_TCP,
82 0 /* is_nonblocking */ );
84 rv = vppcom_session_bind (listen_fd, &endpt);
86 //Make a listener and dispatch
87 rv = vppcom_session_register_listener (listen_fd, listener_cb, 0,
92 fprintf (stderr, "Could not create a listener!\n");