2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /* a simple test program, connects to SDB server, and opens a track-devices session */
19 #include <sys/socket.h>
26 panic( const char* msg )
28 fprintf(stderr, "PANIC: %s: %s\n", msg, strerror(errno));
33 unix_write( int fd, const char* buf, int len )
37 int len2 = write(fd, buf, len);
39 if (errno == EINTR || errno == EAGAIN)
51 unix_read( int fd, char* buf, int len )
55 int len2 = read(fd, buf, len);
57 if (errno == EINTR || errno == EAGAIN)
72 struct sockaddr_in server;
74 const char* request = "track-jdwp";
77 memset( &server, 0, sizeof(server) );
78 server.sin_family = AF_INET;
79 server.sin_port = htons(5037);
80 server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
82 s = socket( PF_INET, SOCK_STREAM, 0 );
83 ret = connect( s, (struct sockaddr*) &server, sizeof(server) );
84 if (ret < 0) panic( "could not connect to server" );
86 /* send the request */
87 len = snprintf( buffer, sizeof buffer, "%04x%s", strlen(request), request );
88 if (unix_write(s, buffer, len) < 0)
89 panic( "could not send request" );
91 /* read the OKAY answer */
92 if (unix_read(s, buffer, 4) != 4)
93 panic( "could not read request" );
95 printf( "server answer: %.*s\n", 4, buffer );
99 char head[5] = "0000";
101 if (unix_read(s, head, 4) < 0)
102 panic("could not read length");
104 if ( sscanf( head, "%04x", &len ) != 1 )
105 panic("could not decode length");
107 if (unix_read(s, buffer, len) != len)
108 panic("could not read data");
110 printf( "received header %.*s (%d bytes):\n%.*s", 4, head, len, len, buffer );