Archive

Archive for the ‘编程语言’ Category

windows7 不支持 AllocateAndGetTcpExTableFromStack

August 8th, 2010 陈毓端 No comments

周末把开发的集成软件放在windows7环境中测试,发现iphlpapi.dll 在windows7下已经放弃支持AllocateAndGetTcpExTableFromStack,AllocateAndGetUdpExTableFromStack

没用办法只能重新修改程序进行重新编译

只能改用 GetExtendedTcpTable 。

具体参考:

http://msdn.microsoft.com/en-us/library/aa365928(VS.85).aspx

Categories: c, delphi, java, 编程语言 Tags:

FastCGI 深入学习第二步

June 28th, 2010 陈毓端 No comments

FastCGI 学习第二步就看看example下的echo.c吧 看看到底是一个什么东西。

源码:

#ifndef lint
static const char rcsid[] = "$Id: echo.c,v 1.5 1999/07/28 00:29:37 roberts Exp $";
#endif /* not lint */

#include "fcgi_config.h"

#include <stdlib.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef _WIN32
#include <process.h>
#else
extern char **environ;
#endif

#include "fcgi_stdio.h"

static void PrintEnv(char *label, char **envp)
{
    printf("%s:<br>\n<pre>\n", label);
    for ( ; *envp != NULL; envp++) {
        printf("%s\n", *envp);
    }
    printf("</pre><p>\n");
}

int main ()
{
    char **initialEnv = environ;
    int count = 0;

    while (FCGI_Accept() >= 0) { //判断是否有请求产生
        char *contentLength = getenv("CONTENT_LENGTH");
        int len;

	printf("Content-type: text/html\r\n"
	    "\r\n"
	    "<title>FastCGI echo</title>"
	    "<h1>FastCGI echo</h1>\n"
            "Request number %d,  Process ID: %d<p>\n", ++count, getpid());

        if (contentLength != NULL) {
            len = strtol(contentLength, NULL, 10);
        }
        else {
            len = 0;
        }

        if (len <= 0) {
	    printf("No data from standard input.<p>\n");
        }
        else {
            int i, ch;

	    printf("Standard input:<br>\n<pre>\n");
            for (i = 0; i < len; i++) {
                if ((ch = getchar()) < 0) {
                    printf("Error: Not enough bytes received on standard input<p>\n");
                    break;
		}
                putchar(ch);
            }
            printf("\n</pre><p>\n");
        }

        PrintEnv("Request environment", environ);
        PrintEnv("Initial environment", initialEnv);
    } /* while */

    return 0;
}

这个demo很简单 核心代码 FCGI_Accept() 判断是否有请求产生 接下的就是写简单的业务逻辑。
Categories: 编程语言 Tags:

深入研究FastCGI 第一步

June 25th, 2010 陈毓端 No comments
说道FastCGI 大家都觉得它比CGI的效率高 具体高在那?很多人会说CGI需要不断的fork 对系统压力大。
其实第一次接触FastCGI是在应用Nginx环境时候,今天再次理下FastCGI 到底是什么?
从官方(http://www.fastcgi.com)的About FastCGI
第一句话就告诉我们:
FastCGI is simple because it is actually CGI with only a few extensions.
FastCGI 其实是一些简单CGI的扩展
Like CGI, FastCGI is also language-independent. For instance, FastCGI provides a way to improve the performance of the thousands of Perl applications that have been written for the Web.
如CGI ,FastCGI也具备语言无关系性。例如,FastCGI 提供一种的方法来提高Prel应用程序的处理能力。
既然是简单的CGI扩展那它的优势在那呢? 难道又是所谓的“重复造车”?
再看看官方的一句重要的解释
Like CGI, FastCGI runs applications in processes isolated from the core Web server, which provides greater security than APIs. (APIs link application code into the core Web server, which means that a bug in one API-based application can corrupt another application or the core server; a malicious API-based application can, for example, steal key security secrets from another application or the core server.)
如CGI , FastCGI 独立运行于WEB服务器的核心进程。并提供大量的安全API。 后面的英文我觉得说的有点严肃。它告诉我们一个问题,FastCGI出现问题之后,以至于不会破坏WEB server的核心进程,一句话WEB server 还可以使用脱离FastCGI的应用。
简单的说就是某些核心应用的托管。 如 托管 Nginx的PHP 解析器进程。
spawn-fcgi.c的核心代码
static int fcgi_spawn_connection(char *appPath, char **appArgv, char *addr, unsigned short port, const char *unixsocket, int fork_count, int child_count, int pid_fd, int nofork);
static int find_user_group(const char *user, const char *group, uid_t *uid, gid_t *gid, const char **username);
最近真的要看看里面的代码。
Nginx的fast-cgi 源码在: src/http/modules/ngx_http_fastcgi_module.c  可以详细的研究下,再次鞭策自己。
FastCGI 的API文档:http://www.fastcgi.com/drupal/node/5
Categories: c, linux, 编程语言 Tags:

Android编程体验

April 9th, 2010 陈毓端 No comments

Android编程体验

当今Mobile OS 虽四足鼎立, 但windows mobile 传统优势正在消失, Symbian颇显老矣, iPhone OS 秉承苹果一贯的作风高高在上,唯有Google Android还算比较优质兼平民,这点从G4就可以看出。
以前倒腾过windows mobile的编程,再看看现在的android编程真是相差蛮多的。虽然两者都是基于java编程。Android更能体现java高度配置的特性。
Android的编程环境搭建也比较容易
安装
1 android-sdk-windows
2 Eclipse + ADT

Android的编程过程比较人性化 以下是重点

重要配置

— layout 界面布局文件
Main.xml 界面核心XML配置
…… 其它更能界面配置

— values 变量定义文件夹
Strings.xml 可以理解为程序的语言包配置文件

— AndroidManifest.xml 十分重要的活动控制中枢 如对话框等活动都要向它登记 比较强势的文件

以下的我的一个例子截图

Categories: java Tags:

mmseg 安装错误 error: ’strncmp’ was not declared in this scope

October 13th, 2009 陈毓端 No comments

mmseg 安装错误

  1. css/UnigramCorpusReader.cpp: In member function 'virtual int css::UnigramCorpusReader::open(const char*, const char*)':
  2. css/UnigramCorpusReader.cpp:89: error: 'strncmp' was not declared in this scope
  3. make[2]: *** [UnigramCorpusReader.lo] Error 1
  4. make[2]: Leaving directory `/lamp/mmseg-0.7.3/src'
  5. make[1]: *** [all-recursive] Error 1
  6. make[1]: Leaving directory `/lamp/mmseg-0.7.3'
  7. make: *** [all] Error 2

解决办法

  1. vim src/css/UnigramCorpusReader.cpp

添加

  1. #include <string.h>

ok!

Categories: c, linux Tags:

delphi 2010 初体验/delphi 2010 验证码

September 17th, 2009 陈毓端 No comments

当delphi ide 从Borland 过户到Embarcadero之后delphi 2010 就是Embarcadero的拳头产品。从delphi 2010的界面到程序布局,都有jbuilder的影子,或者说是更贴近主流IDE。不过和2007比起来,现在还是有点不太习惯。

e69caae591bde5908d

 

 

 

 

 

 

 

 

 

 

 

 

要delphi 2010 验证码(KEY)的可以联系我。

Categories: 编程语言 Tags:

调整im 机器人的数据发送方式

June 24th, 2009 陈毓端 No comments

之前的im机器人是用c的system调用shell的curl来实现数据传送。测试了两天感觉上不是很舒服。决定调整为c的libcurl API发送数据。
就这个小小的调整,涉及到一堆的修改。
最主要的如下:
1 制作 curl发送的动态链接库 so文件
2 修改im机器人的makefile 文件

curl 发送的so动态连接库:
curl_so_head.h
#include “stdio.h”
#include “curl/curl.h”
#include “stdlib.h”
#include “string.h”
#include “dlfcn.h”
void c2(char *msg,char *from,char *robot); // 设置了msg:消息 from:来源 robot:机器人类型

curl_so.c

#include “curl_so_head.h”
void c2(char *msg,char *from,char *robot)
{
CURL *curl;
CURLcode res;
char *s=”&msg=”;
char *s1=”&from=”;
char *s2=”&robot=”;
char pp[200];
strcpy(pp,s);
strcat(pp,msg);
strcat(pp,s1);
strcat(pp,from);
strcat(pp,s2);
strcat(pp,robot);

curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL,”http://xxxx.xxx.xxx.php”);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,pp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}

}
这个是发送调用程序:

void *SoLib;
int (*So)();
SoLib=dlopen(“so_curl.so”,RTLD_LAZY); //so_curl.so是上面操作生成的so文件
So = dlsym( SoLib, “c2″);
(*So)( msg,from,robot); //msg,from,robot表示需要的 消息 来源 robot 机器人类型

修改makefile文件 主要是要在 gcc 后面加上 -ldl 参数 .

ok 目前这项应用就到此吧。后期可能还要加新东西。

Categories: linux, 编程语言 Tags: , , ,

linux c 链接库 so制作及调用

June 23rd, 2009 陈毓端 No comments

最近的一个程序因为比较复杂,需要自己编写so动态链接库来给c语言程序调用。
下面就简单的写下so制作到调用的整个流程。
首先做个头文件
head.h:

  1. /*
  2. head.h
  3.  
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. void method_1(); //未设置参数
  8. void method_2(char *s); // 设置了一个参数

method_1.c:

  1. /*
  2.  method_1.c
  3. */
  4. #include "head.h"
  5. void method_1()
  6. {
  7. printf("我是陈毓端,您执行的是方法1(method_1)");
  8. }

method_2.c

  1. /*
  2. method_2.c
  3. */
  4. #include "head.h"
  5. void method_2(char *s)
  6. {
  7. printf("我是陈毓端,您执行的是方法2(method_2):%s",s);
  8. }

关键一步,生成so(动态链接库)
gcc head.h method_1.c method_2.c -fPIC -shared -o method.so

到现在 method.so 文件已经制做完毕。

接下来是调用
work_so.c

  1. #include  "stdio.h"
  2. #include  "stdlib.h"
  3. #include  "dlfcn.h"
  4. int main()
  5. {
  6. void  *SoLib;
  7. int   (*So)();
  8. SoLib=dlopen("./method.so",RTLD_LAZY); //加载method.so
  9. So   = dlsym( SoLib, "method_1");  //声名method_1方法
  10. (*So)( "" );                                                  //执行method_1方法
  11.  
  12. So    = dlsym(SoLib, "method_2");
  13. (*So)( "method_2" ); //设置参数
  14. }

编译 :

  1. gcc work_so.c -o word_so  -ldl


不出意外 结果为:

我是陈毓端,您执行的是方法1(method_1)我是陈毓端,您执行的是方法1(method_2):method_2

好了这个流程完毕。

Categories: 编程语言 Tags: ,

c 实现urlencode转义

June 23rd, 2009 陈毓端 No comments
  1. #include "stdio.h"
  2. #include "malloc.h"
  3. #include "string.h"
  4. #include "stdlib.h"
  5.  
  6. char from_hex(char ch) {
  7.   return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
  8. }
  9.  
  10.  
  11. char to_hex(char code) {
  12.   static char hex[] = "0123456789abcdef";
  13.   return hex[code & 15];
  14. }
  15.  
  16.  
  17. char *url_encode(char *str) {
  18.   char *pstr = str, *buf = malloc(strlen(str) * 3 + 1), *pbuf = buf;
  19.   while (*pstr) {
  20.     if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') 
  21.       *pbuf++ = *pstr;
  22.     else if (*pstr == ' ') 
  23.       *pbuf++ = '+';
  24.     else 
  25.       *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);
  26.     pstr++;
  27.   }
  28.   *pbuf = '\0';
  29.   return buf;
  30. }
  31.  
  32. char *url_decode(char *str) {
  33.   char *pstr = str, *buf = malloc(strlen(str) + 1), *pbuf = buf;
  34.   while (*pstr) {
  35.     if (*pstr == '%') {
  36.       if (pstr[1] && pstr[2]) {
  37.         *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]);
  38.         pstr += 2;
  39.       }
  40.     } else if (*pstr == '+') { 
  41.       *pbuf++ = ' ';
  42.     } else {
  43.       *pbuf++ = *pstr;
  44.     }
  45.     pstr++;
  46.   }
  47.   *pbuf = '\0';
  48.   return buf;
  49. }
  50. int main(){
  51. char *s1="贪官站住,回头看看,你的脚下充满血迹,你的脑后充满无奈的干枯的目光,你的祖上为你羞愧......---------陈毓端06/23/2009 北京.";
  52. char *s=url_encode(s1);
  53.  printf ("value:%s", s);
  54. }
Categories: 愤青牢骚, 编程语言 Tags: , ,

j2me简单的文字滚动 Ticker

June 18th, 2009 陈毓端 No comments

文字滚动效果在手机上也是很常见的 j2me简单的文字滚动效果实现:

  1. Ticker ticker1 = new Ticker("我是陈毓端,一个80后碌碌无为的程序员....");
  2.  
  3. firstScreen.setTicker(ticker1);

其中firstScreen 表示之前定义的屏幕对象

效果:

321

Categories: java Tags: ,