2012年3月25日日曜日

socket (no android

this is not android program. socket program for c. this is server side.
#include 
#include 
#include 
#include 
#include 
#include 

int main()
{

    int server_sockfd, client_sockfd;
    int server_len, client_len;
    struct sockaddr_in server_address;
    struct sockaddr_in client_address;

    server_sockfd = socket(AF_INET, SOCK_STREAM, 0);

    server_address.sin_family = AF_INET;
    server_address.sin_addr.s_addr = INADDR_ANY;
    server_address.sin_port = 5000;
    server_len = sizeof(server_address);
    bind(server_sockfd, (struct sockaddr *) &server_address, server_len);

    listen(server_sockfd, 5);
    while(1)
    {
        char buf[1024];
        printf("server waiting\n");

        client_sockfd =
            accept(server_sockfd, (struct sockaddr *)&client_address, &client_len);
  printf("server accept\n");

  int allreadsize = 0;
  while(1) {
         int readsize = read(client_sockfd, buf, 1024);
   if (readsize < 0) {
    printf("err\n");
    break;
   } else if(readsize == 0 ) {
    printf("\ndisconnect by client recv size is %d\n", allreadsize);
    break;
   }
   int i = 0;
   int temp = 0;
   for (i= 0;i< readsize;i++) {
    temp = (int)buf[i];
    temp &=0xff;
    printf("%.2x", temp);
   }
   allreadsize += readsize;
  }
  printf("close socket\n");
        close(client_sockfd);
    }
}


this is client side.
#include  
#include  
#include  
#include  
#include  
#include  
#include  


int main(int argc, char **argv)
{

    int sockfd, len, result;
    struct sockaddr_in address;
    char *ch = (char*)argv[1]; 

    sockfd = socket(AF_INET, SOCK_STREAM, 0);

    address.sin_family = AF_INET;
    address.sin_addr.s_addr = inet_addr("127.0.0.1");
    address.sin_port = 5000;
    len = sizeof(address);

    result = connect(sockfd, (struct sockaddr *)&address, len);
    if(result == -1) {
  printf("oops : client1");
 }

 int writesize = 0;
 int l = strlen(ch);
    writesize = write(sockfd, ch, l);
    close(sockfd);
    return 0;
}

source code is here and here. Please suggest your android issue by twitter or mail, I would try to clear up your issue.

2012年3月4日日曜日

Zoom

i try Camera Zoom.
first, i check to suppert Zoom.
Camera.Parameters param = camera.getParameters();
Log.d("camera", "isZoomSupported = " + param.isZoomSupported ());
and i check to support smooth zoom. my nexusOne is not supported.
Camera.Parameters param = camera.getParameters();
Log.d("camera", "isSmoothZoomSupported = " + param.isSmoothZoomSupported ());
i view list of zoom size.
Camera.Parameters param = camera.getParameters();
List ZoomRatislist = param.getZoomRatios ();
for (int i=0;i < ZoomRatislist.size();i++) {
 Log.d("camera", "list " + i + " = " + ZoomRatislist.get(i));
}
it is list of nexusone zoom. passible is between 0 and 12, from x1 to x2.
0 = 100
1 = 104
2 = 112
3 = 117
4 = 125
5 = 131
6 = 141
7 = 148
8 = 158
9 = 166
10 = 178
11 = 186
12 = 200
i set zoom.
Camera.Parameters param = camera.getParameters();
param.setZoom(zoom);
camera.setParameters(param);
source code is here.