. .

Getting Started with Subversion on Windows

June 6th, 2008

by Jared Richardson
http://www.jaredrichardson.net
What will we cover?
Downloading Subversion
Installing Subversion
Adding a new repository
Start a subversion server
Adding users
Get a copy of the code
See your Changes
Put your changes back in the server
Get everyone else’s changes
Adding a new file
Downloading Subversion
You need to download the Windows installer first, but that’s not quite as easy as you might think.  The Subversion download […]

errno=4 : Interrupted System call

June 3rd, 2008

 connect, accept, send, and recv  often cause “Interrupted System call” error when you are writting socket programs
you can solve this problem using:
/* Start with fd just returned by socket(), blocking, SOCK_STREAM… */
while ( connect (fd, &name, namelen) == -1 && errno != EISCONN )
if ( errno != EINTR )
[…]

Recover MySQL root password

June 2nd, 2008

Posted by Vivek on Tuesday April 18, 06 @4:18 pm
You can recover MySQL database server password with following five easy steps.
Step # 1: Stop the MySQL server process.
Step # 2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password
Step # 3: Connect to mysql server as […]

Copy MySQL database from one server to another remote server

June 2nd, 2008

Posted by Vivek on Tuesday November 28, 06 @7:14 pm
Usually you run mysqldump to create database copy:
$ mysqldump -u user -p db-name > db-name.out
Copy db-name.out file using sftp/ssh to remote MySQL server:
$ scp db-name.out user@remote.box.com:/backup
Restore database at remote server (login over ssh):
$ mysql -u user -p db-name < db-name.out
How do I copy a MySQL database […]

MySQL change root password

June 2nd, 2008

MySQL change root password
Posted by Vivek on Monday January 2, 2006 [Last updated: September 29, 2007]
Q. How do I change MySQL root password under Linux, FreeBSD, OpenBSD and UNIX like operating system over ssh / telnet session?
A. Setting up mysql password is one of the essential tasks. root user is MySQL admin account. Remember Linux […]

Sql连接查询和联合查询

June 1st, 2008

连接查询
通过连接运算符可以实现多个表查询。连接是关系数据库模型的主要特点,也是它区别于其它类型数据库管理系统的一个标志。
在关系数据库管理系统中,表建立时各数据之间的关系不必确定,常把一个实体的所有信息存放在一个表中。当检索数据时,通过连接操作查询出存放在多个表中 的不同实体的信息。连接操作给用户带来很大的灵活性,他们可以在任何时候增加新的数据类型。为不同实体创建新的表,尔后通过连接进行查询。
连接可以在SELECT 语句的FROM子句或WHERE子句中建立,似是而非在FROM子句中指出连接时有助于将连接操作与WHERE子句中的搜索条件区分开来。所以,在Transact-SQL中推荐使用这种方法。
SQL-92标准所定义的FROM子句的连接语法格式为:
FROM join_table join_type join_table
[ON (join_condition)]
其中join_table指出参与连接操作的表名,连接可以对同一个表操作,也可以对多表操作,对同一个表操作的连接又称做自连接。
join_type 指出连接类型,可分为三种:内连接、外连接和交叉连接。内连接(INNER JOIN)使用比较运算符进行表间某(些)列数据的比较操作,并列出这些表中与连接条件相匹配的数据行。根据所使用的比较方式不同,内连接又分为等值连 接、自然连接和不等连接三种。
网管联盟bitsCN@com
外连接 分为左外连接(LEFT OUTER JOIN或LEFT JOIN)、右外连接(RIGHT OUTER JOIN或RIGHT JOIN)和全外连接(FULL OUTER JOIN或FULL JOIN)三种。与内连接不同的是,外连接不只列出与连接条件相匹配的行,而是列出左表(左外连接时)、右表(右外连接时)或两个表(全外连接时)中所有 符合搜索条件的数据行。
交叉连接(CROSS JOIN)没有WHERE 子句,它返回连接表中所有数据行的笛卡尔积,其结果集合中的数据行数等于第一个表中符合查询条件的数据行数乘以第二个表中符合查询条件的数据行数。
连接操作中的ON (join_condition) 子句指出连接条件,它由被连接表中的列和比较运算符、逻辑运算符等构成。
无论哪种连接都不能对text、ntext和image数据类型列进行直接连接,但可以对这三种列进行间接连接。例如:
SELECT p1.pub_id,p2.pub_id,p1.pr_info
FROM pub_info AS p1 INNER JOIN pub_info AS p2
ON DATALENGTH(p1.pr_info)=DATALENGTH(p2.pr_info)
(一)内连接
内连接查询操作列出与连接条件匹配的数据行,它使用比较运算符比较被连接列的列值。内连接分三种:
1、等值连接:在连接条件中使用等于号(=)运算符比较被连接列的列值,其查询结果中列出被连接表中的所有列,包括其中的重复列。 中国网管论坛bbs.bitsCN.com
2、不等连接: 在连接条件使用除等于运算符以外的其它比较运算符比较被连接的列的列值。这些运算符包括>、>=、<=、<、!>、!<和<>。
3、自然连接:在连接条件中使用等于(=)运算符比较被连接列的列值,但它使用选择列表指出查询结果集合中所包括的列,并删除连接表中的重复列。
例,下面使用等值连接列出authors和publishers表中位于同一城市的作者和出版社:
SELECT *
FROM authors AS a INNER JOIN publishers AS p
ON a.city=p.city
又如使用自然连接,在选择列表中删除authors 和publishers 表中重复列(city和state):
SELECT a.*,p.pub_id,p.pub_name,p.country
FROM authors AS a INNER […]

gSOAP Tutorial : Part I

May 30th, 2008

A. define the interface

int ns_add( int x, int y, int* sum);

note that the return value is the used to determining the status of SOAP request, parameter x and y are two integer to be added. pay special attention to the last parameter “sum” which is a “pointer” to sum calculated.

B. Generate stub and skeleton

Run the stub/skeleton compiler

soapcpp2 -c add.h

the option “-c” tells stub/skeleton compiler to generate the C code instead of Cpp code. Now you will find files generate by the compiler in current directory. Pay attention to the file soapStub.h with function “soap_call_ns_add” declared in it . Your client code will invoke this function to fulfill a web service.

C. Build the client

with gSOAP, building a SOAP client can be summarized as :

  • Init SOAP runtime
  • Invoke remote web service method generated by stub/skeleton compiler

// code for client: client.c
#include “soapH.h”
int main()
{
struct soap s;
int sum=0;
int a=3;
int b=4;
soap_init(&s);
if(soap_call_ns_add(&s,”localhost:50000″,NULL,a,b,∑)==SOAP_OK)
{
printf(”%d+%d=%d\n”,a,b,sum);
}
else
{
soap_print_fault(&s,stderr);
}
soap_end(&s);
soap_done(&s);
return 0;
}

remember to add the following lines of code into your client program, namespace is a mapping table used by codes generated by stub compiler.

struct Namespace namespaces[] =
{
{ “SOAP-ENV”, “http://schemas.xmlsoap.org/soap/envelope/” },
{ “SOAP-ENC”,”http://schemas.xmlsoap.org/soap/encoding/”},
{ “xsi”, “http://www.w3.org/1999/XMLSchema-instance” },
{ “xsd”, “http://www.w3.org/1999/XMLSchema” },
{ “ns”, “urn:Calc”},
{ NULL, NULL }
};
compile the client source files (remeber to copy stdsoap2.h and stdsoap2.c into current directory):

gcc -o client client.c soapC.c soapClient.c stdsoap2.c

D. Build the server

Build a SOAP using code the generated by gSOAP can be summarized as:

  • Bind and listen for a client connection
  • Process request ( using soap_serve)

code for server: server.c
#include “soapH.h”
int main()
{
struct soap soap;
int m, s; // master and slave sockets
soap_init(&soap);
m = soap_bind(&soap, “localhost”, 50000, 100);
if (m < 0)
soap_print_fault(&soap, stderr);
else
{
fprintf(stderr, “Socket connection successful: master socket = %d\n”, m);
while(1)
{
s = soap_accept(&soap);
if (s < 0)
{
soap_print_fault(&soap, stderr);
break;
}

if (soap_serve(&soap) != SOAP_OK) // process RPC request
soap_print_fault(&soap, stderr); // print error
fprintf(stdout, “request served\n”);

soap_end(&soap); // clean up everything and close socket
}
}
soap_done(&soap); // close master socket and detach environment
}

int ns_add(struct soap* soap, int x, int y,int * sum)
{
*sum=x+y;
return SOAP_OK;
}
struct Namespace namespaces[] =
{
{ “SOAP-ENV”, “http://schemas.xmlsoap.org/soap/envelope/” },
{ “SOAP-ENC”,”http://schemas.xmlsoap.org/soap/encoding/”},
{ “xsi”, “http://www.w3.org/1999/XMLSchema-instance” },
{ “xsd”, “http://www.w3.org/1999/XMLSchema” },
{ “ns”, “urn:Calc”},
{ NULL, NULL }
};
compile the server source files:

gcc -o server server.c soapC.c soapServer.c stdsoap2.c

E. Test

run the server

./server

run the client

./client

you will get the following line on the screen:

3+4=7

Yeah. That is all you need to build a simple service

For more information about gSOAP, please visit the author’s website

-->

Introduction:
The gSOAP toolkit provides a SOAP/XML-to-C/C++ language binding to ease the development of SOAP/XML Web services and client application in C and C++.The gSOAP uses stub and skeleton compiler to map C or C++ types ( both build-in types and user-defined types) into XML data types. It’ s a open source toolkit and can be […]

MySQL FAQ

May 29th, 2008

Q1. How to start mysqld manully on Linux

A1. First, make sure that you have the root previlege, then using the following command:
/etc/init.d/mysql start
Q2. How to Set password for user “root”
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h linux.site password ‘new-password’

Linux 下的Chm 文件阅读器

May 29th, 2008

网络上流传的很多文档,包括一些电子书,采用的是微软的chm格式打包,无法直接在linux下阅读,虽然目前有一些工具如 chmsee , xchm 提供了不错的阅读chm文件的方法,不过它们的安装过程实在是麻烦(主要是各种库的依赖性,往往是装了这个库又依赖那个,真是头大)。还好最近发现了一个 firefox 下阅读 chm 文件的插件,好用的不得了。具体安装过程参考:http://www.info-life.cn/2008/05/chm-viewer-for-linux-chm-reader.html

给linux添加新硬盘的经过

May 20th, 2008

网络上搜索到的一篇linux 添加硬盘的记录。

 

 

最近又出了不少新网络游戏,游戏更新服务器空间不足了。于是就想要给服务器上再加一块新硬盘。
游戏服务器是mandrake2005的系统,原来装有一块160G的硬盘,准备再加一块80G的。
拿到新盘以后就关机、插线、重开机。一切正常。
进入系统以后,查看 /dev下多了个 hdb,然后开始分区
执行  fdisk /dev/hdb
进入 fdisk的界面,打命令 n新建一个分区。
然后提示选择e(扩展分区)或p(主分区),这时输入了e创建扩展分区。
然后提示让输入分区编号(1-4),输入了1
接下来按提示输入起始扇区号和结束扇区号,由于只打算分一个区,都选择了默认值
最后输入命令 w 保存退出。
程式出现以下提示
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
这样分区就完成了。
接下来格式化分区:
执行 mkfs.ext3 /dev/hdb1
预料中应该是出现格式化的过程,结果确是提示 /dev/hdb1: Invalid argument passed to ext2 library while setting up superblock
以为是分区还没有加载上,重启机子后重新执行格式化命令,问题依旧。
fdisk -l /dev/hdb 查看,分区hdb1已正常存在。
百度里搜索此提示,发现有不少人碰到同样的问题,确都没有给了解决方案。
无奈之下去google搜索英文网站,找了几个同样的问题,半读半猜之后看到了解决办法。
删掉刚刚划分出来的分区,然后重新分区,并在选择e(扩展分区)还是p(主分区)的时候选择了创建主分区,然后依次执行,顺利分完区。
接下来再次执行格式划命令 mkfs.ext3 /dev/hdb1
此时程式顺利进入格式化界面,开始格式化。
经过二十多分钟的漫长等待,格式化终于完成.问题解决!
接下来挂载新加的硬盘分区:
原来服务器存放游戏的目录结构为: update目下有个game目录,里面放着任何网络游戏,update做samba共享,管理员用户能够读写删,同时将game目录做samba共享,可匿名访问,只有读和执行权限。
此时在update目录下新建了game2目录: mkdir /update/game2
然后将新添加的硬盘分区挂载到此目录 mount /dev/hdb1 /update/game2
然后修改samba的配置文档,将game2目录也共享出来,设为和game同样权限,可匿名访问,可读、执行。
service smb restart 重启samba共享服务
至此服务器扩容成功。
为了以后每次重启服务器后不用再手工挂载新加的分区,还要再修改/etc/fstab文档,让系统启动时自动挂载。
vi /etc/fstab
在文档末尾添加一行 /dev/hdb1 /update/game2 ext3 default 1 2
保存退出。
至此任何工作全部完成。

Page: 1 2 3 ... 10