goahead源碼
1. 什麼是sql server 嵌入式簡包
嵌入式sql語言是將sql語句直接嵌入到程序的源代碼中,與其他程序設計語言語句混宏態合.
嵌入式sql的用途:它是資料庫應用程序的一種開發方法.是一種應用程序進行數據銀絕旁庫訪問時所鋒橡採取的編程式資料庫語言.
2. 網頁開發
這你問我們沒用,起碼你得有網站源碼或者人家提供給你的api
3. firefox支持goahead-webs嗎
支持的,辯銷GoAhead WebServer,它是一個源碼,免費、功能強和缺大、可以在多個平台運行喚灶辯的嵌入式WebServer。
4. 誰知道如何在ubuntu系統下安裝goahead啊
goahead2.5源碼包,裡面有安裝說明的,你的另外一個提問里,也給你加了安裝說明。
5. goahead嵌入式web中 ,websWrite(wp, T("一段中文"))這個函數寫到頁面時 中文為亂碼如何解決呢
主要編碼方式 chartset 設置成 utf-8就行了。本來是UTF8編碼但是你沒有聲明的話,瀏覽器默認就按GB2312處理了,所以就成亂碼了。
6. 誰有辯論賽計時器的源代碼
客戶端
/* Client side of an ftp service. Actions:
- connect to server and request service
- send size-of-sile info to server
- start receiving file from server
- close connection
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <errno.h>
#define SERVER_PORT_ID 6081
#define CLIENT_PORT_ID 6086
#define SERVER_HOST_ADDR "128.119.40.186"
/* gaia.cs.umass.e */
#define MAXSIZE 512
#define ACK 2
#define NACK 3
#define REQUESTFILE 100
#define COMMANDNOTSUPPORTED 150
#define COMMANDSUPPORTED 160
#define BADFILENAME 200
#define FILENAMEOK 400
#define STARTTRANSFER 500
int readn(int sd,char *ptr,int size);
int writen(int sd,char *ptr,int size);
main(int argc,char *argv[])
{
int sockid, newsockid,i,getfile,ack,msg,msg_2,c,len;
int no_writen,start_xfer, num_blks,num_last_blk;
struct sockaddr_in my_addr, server_addr;
FILE *fp;
char in_buf[MAXSIZE];
if(argc != 2) {printf("error: usage : sftp filename\n"); exit(0);}
no_writen = 0;
num_blks = 0;
num_last_blk = 0;
len = strlen(argv[1]);
printf("client: creating socket\n");
if ((sockid = socket(AF_INET,SOCK_STREAM,0)) < 0)
{ printf("client: socket error : %d\n", errno); exit(0);
}
printf("client: binding my local socket\n");
bzero((char *) &my_addr,sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
my_addr.sin_port = htons(CLIENT_PORT_ID);
if (bind(sockid ,(struct sockaddr *) &my_addr,sizeof(my_addr)) < 0)
{printf("client: bind error :%d\n", errno); exit(0);
}
printf("client: starting connect\n");
bzero((char *) &server_addr,sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = inet_addr(SERVER_HOST_ADDR);
server_addr.sin_port = htons(SERVER_PORT_ID);
if (connect(sockid ,(struct sockaddr *) &server_addr,
sizeof(server_addr)) < 0)
{printf("client: connect error :%d\n", errno); exit(0);
}
/* Once we are here, we've got a connection to the server */
/* tell server that we want to get a file */
getfile = htons(REQUESTFILE);
printf("client: sending command request to ftp server\n");
if((writen(sockid,(char *)&getfile,sizeof(getfile))) < 0)
{printf("client: write error :%d\n", errno); exit(0);}
/* want for go-ahead from server */
msg = 0;
if((readn(sockid,(char *)&msg,sizeof(msg)))< 0)
{printf("client: read error :%d\n", errno); exit(0); }
msg = ntohs(msg);
if (msg==COMMANDNOTSUPPORTED) {
printf("client: server refused command. goodbye\n");
exit(0);
}
else
printf("client: server replied %d, command supported\n",msg);
/* send file name to server */
printf("client: sending filename\n");
if ((writen(sockid,argv[1],len))< 0)
{printf("client: write error :%d\n", errno); exit(0);}
/* see if server replied that file name is OK */
msg_2 = 0;
if ((readn(sockid,(char *)&msg_2,sizeof(msg_2)))< 0)
{printf("client: read error :%d\n", errno); exit(0); }
msg_2 = ntohs(msg_2);
if (msg_2 == BADFILENAME) {
printf("client: server reported bad file name. goodbye.\n");
exit(0);
}
else
printf("client: server replied %d, filename OK\n",msg_2);
/* CLIENT KNOWS SERVER HAS BEEN ABLE TO OPEN THE FILE IN READ
MODE AND IS ASKING FOR GO-AHEAD*/
/* CLIENT NOW OPENS A COPY OF THE FILE IN WRITE MODE AND SENDS
THE GOAHEAD TO SERVER*/
printf("client: sending start transfer command\n");
start_xfer = STARTTRANSFER;
start_xfer = htons(start_xfer);
if ((writen(sockid,(char *)&start_xfer,sizeof(start_xfer)))< 0)
{printf("client: write error :%d\n", errno); exit(0);
}
if ((fp = fopen(argv[1],"w")) == NULL)
{printf(" client: local open file error \n");exit(0);}
/*NOW THE CLIENT IS READING INFORMATION FROM THE SERVER REGARDING HOW MANY
FULL BLOCKS OF SIZE MAXSIZE IT CAN EXPECT. IT ALSO RECEIVES THE NUMBER
OF BYTES REMAINING IN THE LAST PARTIALLY FILLED BLOCK, IF ANY */
if((readn(sockid,(char *)&num_blks,sizeof(num_blks))) < 0)
{printf("client: read error on nblocks :%d\n",errno);exit(0);}
num_blks = ntohs(num_blks);
printf("client: server responded: %d blocks in file\n",num_blks);
ack = ACK;
ack = htons(ack);
if((writen(sockid,(char *)&ack,sizeof(ack))) < 0)
{printf("client: ack write error :%d\n",errno);exit(0);
}
if((readn(sockid,(char *)&num_last_blk,sizeof(num_last_blk))) < 0)
{printf("client: read error :%d on nbytes\n",errno);exit(0);}
num_last_blk = ntohs(num_last_blk);
printf("client: server responded: %d bytes last blk\n",num_last_blk);
if((writen(sockid,(char *)&ack,sizeof(ack))) < 0)
{printf("client: ack write error :%d\n",errno);exit(0);
}
/* BEGIN READING BLOCKS BEING SENT BY SERVER */
printf("client: starting to get file contents\n");
for(i= 0; i < num_blks; i ++) {
if((readn(sockid,in_buf,MAXSIZE)) < 0)
{printf("client: block error read: %d\n",errno);exit(0);}
no_writen = fwrite(in_buf,sizeof(char),MAXSIZE,fp);
if (no_writen == 0) {printf("client: file write error\n");exit(0);}
if (no_writen != MAXSIZE)
{printf("client: file write error : no_writen is less\n");exit(0);}
/* send an ACK for this block */
if((writen(sockid,(char *)&ack,sizeof(ack))) < 0)
{printf("client: ack write error :%d\n",errno);exit(0);}
printf(" %d...",i);
}
/*IF THERE IS A LAST PARTIALLY FILLED BLOCK, READ IT */
if (num_last_blk > 0) {
printf("%d\n",num_blks);
if((readn(sockid,in_buf,num_last_blk)) < 0)
{printf("client: last block error read :%d\n",errno);exit(0);}
no_writen = fwrite(in_buf,sizeof(char),num_last_blk,fp);
if (no_writen == 0)
{printf("client: last block file write err :%d\n",errno);exit(0);}
if (no_writen != num_last_blk)
{printf("client: file write error : no_writen is less 2\n");exit(0);}
if((writen(sockid,(char *)&ack,sizeof(ack))) < 0)
{printf("client :ack write error :%d\n",errno);exit(0);}
}
else printf("\n");
/*FILE TRANSFER ENDS. CLIENT TERMINATES AFTER CLOSING ALL ITS FILES
AND SOCKETS*/
fclose(fp);
printf("client: FILE TRANSFER COMPLETE\n");
close(sockid);
}
/* DUE TO THE FACT THAT BUFFER LIMITS IN KERNEL FOR THE SOCKET MAY BE
REACHED, IT IS POSSIBLE THAT READ AND WRITE MAY RETURN A POSITIVE VALUE
LESS THAN THE NUMBER REQUESTED. HENCE WE CALL THE TWO PROCEDURES
BELOW TO TAKE CARE OF SUCH EXIGENCIES */
int readn(int sd,char *ptr,int size)
{ int no_left,no_read;
no_left = size;
while (no_left > 0)
{ no_read = read(sd,ptr,no_left);
if(no_read <0) return(no_read);
if (no_read == 0) break;
no_left -= no_read;
ptr += no_read;
}
return(size - no_left);
}
int writen(int sd,char *ptr,int size)
{ int no_left,no_written;
no_left = size;
while (no_left > 0)
{ no_written = write(sd,ptr,no_left);
if(no_written <=0) return(no_written);
no_left -= no_written;
ptr += no_written;
}
return(size - no_left);
}
服務端
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <errno.h>
#define MY_PORT_ID 6081
#define MAXLINE 256
#define MAXSIZE 512
#define ACK 2
#define NACK 3
#define REQUESTFILE 100
#define COMMANDNOTSUPPORTED 150
#define COMMANDSUPPORTED 160
#define BADFILENAME 200
#define FILENAMEOK 400
int writen(int sd,char *ptr,int size);
int readn(int sd,char *ptr,int size);
main() {
int sockid, newsd, pid, clilen;
struct sockaddr_in my_addr, client_addr;
printf("server: creating socket\n");
if ((sockid = socket(AF_INET,SOCK_STREAM,0)) < 0)
{printf("server: socket error : %d\n", errno); exit(0); }
printf("server: binding my local socket\n");
bzero((char *) &my_addr,sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(MY_PORT_ID);
my_addr.sin_addr.s_addr = htons(INADDR_ANY);
if (bind(sockid ,(struct sockaddr *) &my_addr,sizeof(my_addr)) < 0)
{printf("server: bind error :%d\n", errno); exit(0); }
printf("server: starting listen \n");
if (listen(sockid,5) < 0)
{ printf("server: listen error :%d\n",errno);exit(0);}
while(1==1) {
/* ACCEPT A CONNECTION AND THEN CREATE A CHILD TO DO THE WORK */
/* LOOP BACK AND WAIT FOR ANOTHER CONNECTION */
printf("server: starting accept\n");
if ((newsd = accept(sockid ,(struct sockaddr *) &client_addr,
&clilen)) < 0)
{printf("server: accept error :%d\n", errno); exit(0); }
printf("server: return from accept, socket for this ftp: %d\n",
newsd);
if ( (pid=fork()) == 0) {
/* CHILD PROC STARTS HERE. IT WILL DO ACTUAL FILE TRANSFER */
close(sockid); /* child shouldn't do an accept */
doftp(newsd);
close (newsd);
exit(0); /* child all done with work */
}
/* PARENT CONTINUES BELOW HERE */
close(newsd); /* parent all done with client, only child */
} /* will communicate with that client from now on */
}
7. 求FTP Server和FTP Client的源代碼,要java或C++的,
客戶端
/* Client side of an ftp service. Actions:
- connect to server and request service
- send size-of-sile info to server
- start receiving file from server
- close connection
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <errno.h>
#define SERVER_PORT_ID 6081
#define CLIENT_PORT_ID 6086
#define SERVER_HOST_ADDR "128.119.40.186"
/* gaia.cs.umass.e */
#define MAXSIZE 512
#define ACK 2
#define NACK 3
#define REQUESTFILE 100
#define COMMANDNOTSUPPORTED 150
#define COMMANDSUPPORTED 160
#define BADFILENAME 200
#define FILENAMEOK 400
#define STARTTRANSFER 500
int readn(int sd,char *ptr,int size);
int writen(int sd,char *ptr,int size);
main(int argc,char *argv[])
{
int sockid, newsockid,i,getfile,ack,msg,msg_2,c,len;
int no_writen,start_xfer, num_blks,num_last_blk;
struct sockaddr_in my_addr, server_addr;
FILE *fp;
char in_buf[MAXSIZE];
if(argc != 2) {printf("error: usage : sftp filename\n"); exit(0);}
no_writen = 0;
num_blks = 0;
num_last_blk = 0;
len = strlen(argv[1]);
printf("client: creating socket\n");
if ((sockid = socket(AF_INET,SOCK_STREAM,0)) < 0)
{ printf("client: socket error : %d\n", errno); exit(0);
}
printf("client: binding my local socket\n");
bzero((char *) &my_addr,sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
my_addr.sin_port = htons(CLIENT_PORT_ID);
if (bind(sockid ,(struct sockaddr *) &my_addr,sizeof(my_addr)) < 0)
{printf("client: bind error :%d\n", errno); exit(0);
}
printf("client: starting connect\n");
bzero((char *) &server_addr,sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = inet_addr(SERVER_HOST_ADDR);
server_addr.sin_port = htons(SERVER_PORT_ID);
if (connect(sockid ,(struct sockaddr *) &server_addr,
sizeof(server_addr)) < 0)
{printf("client: connect error :%d\n", errno); exit(0);
}
/* Once we are here, we've got a connection to the server */
/* tell server that we want to get a file */
getfile = htons(REQUESTFILE);
printf("client: sending command request to ftp server\n");
if((writen(sockid,(char *)&getfile,sizeof(getfile))) < 0)
{printf("client: write error :%d\n", errno); exit(0);}
/* want for go-ahead from server */
msg = 0;
if((readn(sockid,(char *)&msg,sizeof(msg)))< 0)
{printf("client: read error :%d\n", errno); exit(0); }
msg = ntohs(msg);
if (msg==COMMANDNOTSUPPORTED) {
printf("client: server refused command. goodbye\n");
exit(0);
}
else
printf("client: server replied %d, command supported\n",msg);
/* send file name to server */
printf("client: sending filename\n");
if ((writen(sockid,argv[1],len))< 0)
{printf("client: write error :%d\n", errno); exit(0);}
/* see if server replied that file name is OK */
msg_2 = 0;
if ((readn(sockid,(char *)&msg_2,sizeof(msg_2)))< 0)
{printf("client: read error :%d\n", errno); exit(0); }
msg_2 = ntohs(msg_2);
if (msg_2 == BADFILENAME) {
printf("client: server reported bad file name. goodbye.\n");
exit(0);
}
else
printf("client: server replied %d, filename OK\n",msg_2);
/* CLIENT KNOWS SERVER HAS BEEN ABLE TO OPEN THE FILE IN READ
MODE AND IS ASKING FOR GO-AHEAD*/
/* CLIENT NOW OPENS A COPY OF THE FILE IN WRITE MODE AND SENDS
THE GOAHEAD TO SERVER*/
printf("client: sending start transfer command\n");
start_xfer = STARTTRANSFER;
start_xfer = htons(start_xfer);
if ((writen(sockid,(char *)&start_xfer,sizeof(start_xfer)))< 0)
{printf("client: write error :%d\n", errno); exit(0);
}
if ((fp = fopen(argv[1],"w")) == NULL)
{printf(" client: local open file error \n");exit(0);}
/*NOW THE CLIENT IS READING INFORMATION FROM THE SERVER REGARDING HOW MANY
FULL BLOCKS OF SIZE MAXSIZE IT CAN EXPECT. IT ALSO RECEIVES THE NUMBER
OF BYTES REMAINING IN THE LAST PARTIALLY FILLED BLOCK, IF ANY */
if((readn(sockid,(char *)&num_blks,sizeof(num_blks))) < 0)
{printf("client: read error on nblocks :%d\n",errno);exit(0);}
num_blks = ntohs(num_blks);
printf("client: server responded: %d blocks in file\n",num_blks);
ack = ACK;
ack = htons(ack);
if((writen(sockid,(char *)&ack,sizeof(ack))) < 0)
{printf("client: ack write error :%d\n",errno);exit(0);
}
if((readn(sockid,(char *)&num_last_blk,sizeof(num_last_blk))) < 0)
{printf("client: read error :%d on nbytes\n",errno);exit(0);}
num_last_blk = ntohs(num_last_blk);
printf("client: server responded: %d bytes last blk\n",num_last_blk);
if((writen(sockid,(char *)&ack,sizeof(ack))) < 0)
{printf("client: ack write error :%d\n",errno);exit(0);
}
/* BEGIN READING BLOCKS BEING SENT BY SERVER */
printf("client: starting to get file contents\n");
for(i= 0; i < num_blks; i ++) {
if((readn(sockid,in_buf,MAXSIZE)) < 0)
{printf("client: block error read: %d\n",errno);exit(0);}
no_writen = fwrite(in_buf,sizeof(char),MAXSIZE,fp);
if (no_writen == 0) {printf("client: file write error\n");exit(0);}
if (no_writen != MAXSIZE)
{printf("client: file write error : no_writen is less\n");exit(0);}
/* send an ACK for this block */
if((writen(sockid,(char *)&ack,sizeof(ack))) < 0)
{printf("client: ack write error :%d\n",errno);exit(0);}
printf(" %d...",i);
}
/*IF THERE IS A LAST PARTIALLY FILLED BLOCK, READ IT */
if (num_last_blk > 0) {
printf("%d\n",num_blks);
if((readn(sockid,in_buf,num_last_blk)) < 0)
{printf("client: last block error read :%d\n",errno);exit(0);}
no_writen = fwrite(in_buf,sizeof(char),num_last_blk,fp);
if (no_writen == 0)
{printf("client: last block file write err :%d\n",errno);exit(0);}
if (no_writen != num_last_blk)
{printf("client: file write error : no_writen is less 2\n");exit(0);}
if((writen(sockid,(char *)&ack,sizeof(ack))) < 0)
{printf("client :ack write error :%d\n",errno);exit(0);}
}
else printf("\n");
/*FILE TRANSFER ENDS. CLIENT TERMINATES AFTER CLOSING ALL ITS FILES
AND SOCKETS*/
fclose(fp);
printf("client: FILE TRANSFER COMPLETE\n");
close(sockid);
}
/* DUE TO THE FACT THAT BUFFER LIMITS IN KERNEL FOR THE SOCKET MAY BE
REACHED, IT IS POSSIBLE THAT READ AND WRITE MAY RETURN A POSITIVE VALUE
LESS THAN THE NUMBER REQUESTED. HENCE WE CALL THE TWO PROCEDURES
BELOW TO TAKE CARE OF SUCH EXIGENCIES */
int readn(int sd,char *ptr,int size)
{ int no_left,no_read;
no_left = size;
while (no_left > 0)
{ no_read = read(sd,ptr,no_left);
if(no_read <0) return(no_read);
if (no_read == 0) break;
no_left -= no_read;
ptr += no_read;
}
return(size - no_left);
}
int writen(int sd,char *ptr,int size)
{ int no_left,no_written;
no_left = size;
while (no_left > 0)
{ no_written = write(sd,ptr,no_left);
if(no_written <=0) return(no_written);
no_left -= no_written;
ptr += no_written;
}
return(size - no_left);
}
服務端
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <errno.h>
#define MY_PORT_ID 6081
#define MAXLINE 256
#define MAXSIZE 512
#define ACK 2
#define NACK 3
#define REQUESTFILE 100
#define COMMANDNOTSUPPORTED 150
#define COMMANDSUPPORTED 160
#define BADFILENAME 200
#define FILENAMEOK 400
int writen(int sd,char *ptr,int size);
int readn(int sd,char *ptr,int size);
main() {
int sockid, newsd, pid, clilen;
struct sockaddr_in my_addr, client_addr;
printf("server: creating socket\n");
if ((sockid = socket(AF_INET,SOCK_STREAM,0)) < 0)
{printf("server: socket error : %d\n", errno); exit(0); }
printf("server: binding my local socket\n");
bzero((char *) &my_addr,sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(MY_PORT_ID);
my_addr.sin_addr.s_addr = htons(INADDR_ANY);
if (bind(sockid ,(struct sockaddr *) &my_addr,sizeof(my_addr)) < 0)
{printf("server: bind error :%d\n", errno); exit(0); }
printf("server: starting listen \n");
if (listen(sockid,5) < 0)
{ printf("server: listen error :%d\n",errno);exit(0);}
while(1==1) {
/* ACCEPT A CONNECTION AND THEN CREATE A CHILD TO DO THE WORK */
/* LOOP BACK AND WAIT FOR ANOTHER CONNECTION */
printf("server: starting accept\n");
if ((newsd = accept(sockid ,(struct sockaddr *) &client_addr,
&clilen)) < 0)
{printf("server: accept error :%d\n", errno); exit(0); }
printf("server: return from accept, socket for this ftp: %d\n",
newsd);
if ( (pid=fork()) == 0) {
/* CHILD PROC STARTS HERE. IT WILL DO ACTUAL FILE TRANSFER */
close(sockid); /* child shouldn't do an accept */
doftp(newsd);
close (newsd);
exit(0); /* child all done with work */
}
/* PARENT CONTINUES BELOW HERE */
close(newsd); /* parent all done with client, only child */
} /* will communicate with that client from now on */
}
8. 怎樣用asp創建聊天室(高分)
用ASP建造自己的聊天室
聊天室想必你一定去過吧,但想不想建立自己的聊天室呢?其實這一點都不難,Active Server Script提供了Application對象和Session對象,Application對象代表了一個Active Server應用程序,也就是一個Web網頁,Session對象則表示一個用戶,代表一個用戶對這個頁面的一次訪問,通過Application對象可以讓訪問它的所有用戶共享信息,並可以在Web伺服器運行期間持久地保存數據,而Session對象也可以在用戶的一次訪問期間持久地保持數據,利用這兩個對象,悄慧就可以十分方便地建造自己的Chat應用程序。
---- 一、Application對象:
---- 1.屬性:Application對象沒有內置的屬性,但用戶可以定義自己的屬性:
---- Application(「屬性名稱」)=值,一旦分配了屬性,它就會一直存在,直到Web伺服器關閉服務,而且它能被所有用戶讀取,所以可以用它在用戶之間發送談話內容。
---- 2.方法:當兩個用戶同時對Application屬性的值進行寫入操作時,會出現渣埋一方的修改被另一方的操作直接覆蓋掉的情況,為了避免這種現象,用戶可以調用Lock方法進行鎖定,這樣只有當前用戶才能夠對Application的屬性進行操作,用戶完成操作後調用Unlock方法解鎖,使得其他用戶也可以修改Application的屬性。
---- 3.事件:創建Active Server應用程序需要在Web伺服器上存放應用程序的虛擬主目錄下創啟梁答建Global.asa文件,它含有Application對象和Session對象的事件處理常式,通常,Application_Onstart事件用來定義應用級的屬性。
---- 二、創建一個Chat應用程序:程序運行時如下圖所示(略)
---- 1.設置應用程序的變數:這里需建立兩個應用程序級的變數,gchars數組用來存放用戶的談話內容,gcounter用做計數器,控制頁面的顯示行數,在這里我們讓頁面最多顯示最近的10行談話內容。當應用程序啟動時這些變數必須進行初始化,所以它們的創建都要在Global.asa文件中的Application_onstart事件中:
< script language="vbscript" runat="server" >
sub application_onstart()
dim lchars(10)
application("gchars")=lchars
application("gcounter")=0
end sub
< /script >
---- 2.確定處理ASP的方式:當用戶第一次請求這個ASP文件時,用的是GET方法,然後,當用戶輸入完談話內容後提交時用的是POST方法,在這里表單是向自身提交的,所以這個ASP文件會被再次請求,我們通過測試Request . ServerVariales(「Request_Method」)變數來確定文件被請求的方式:IF Request . ServerVariales(「Request_Method」)=「POST」 then
---- 3.確定講話者:當用戶第一次提交談話內容時需輸入自己的姓名,一旦在txtname框中輸入數據後,程序將建立一個會話級變數來存放用戶姓名,並自動顯示在txtname框中,用戶就不需再次輸入了,除非你想用另一個名字加入會談。
IF len(request(「txtname」)) >0 then
Session(「ssname」)=request(「txtname」)
End if
< h5 >您的姓名:
< input type=「type」 name=「txtname」
length=「20」 value=< %=session(「ssname」)% > >
----
---- 4.處理用戶的談話內容:首先要確定已經為Chat寫入的談話行數,為方便閱讀,在這里將顯示行數限定為10行,如果Application(「gcounter」)大於9,則將其置為0,然後將談話者姓名和內容一起存放到Application(「gchars」)數組中:
Application(「gchars」)
(Application(「gcounter」))=Session(「ssname」) &
「:」 & request(txttalk)
然後將計數器加1:Application(「gcounter」) =Application(「gcounter」)+1
---- 5.將數組內容寫入到客戶的瀏覽器中:用戶提交談話內容後,程序必須將數組內容寫到客戶的瀏覽器中,讓聊天室中的所有人都能看到被提交的談話內容:
if application("gcounter")=0 then
lstemp=application("gchars")(0)
else
for x=0 to application("gcounter")-1
lstemp=lstemp & "< br >" & application("gchars")(x)
next
end if
---- 最後,用Response.write方法將lstemp變數的值寫到客戶的瀏覽器中去:
response.write lstemp
---- 下面給出Default.asp的完整代碼:
< %response.expires=0
response.buffer=true% >
< html >< head >< title >Chat sample< /title >< /head >
< body >< center >
< h3 >我的聊天室< /h3 >< /center >< hr >
< % if request.servervariables("request_method")="POST" then
if len(request("txtname")) >0 then
session("ssname")=request("txtname")
end if
application.lock
mcounter=application("gcounter")
mchars=application("gchars")
if mcounter >9 then
mcounter=0
end if
mchars(mcounter)=session("ssname")
& ":" & request("txttalk")
mcounter=mcounter+1
application("gcounter")=mcounter
application("gchars")=mchars
application.unlock
end if % >
< % if application("gcounter")=0 then
lstemp=application("gchars")(0)
else
for x=0 to application("gcounter")-1
lstemp=lstemp & "< br >" & application("gchars")(x)
next
end if
response.write lstemp % >
< hr >< center >
< form action="default.asp" method=post name="aspform" >
< b >< a href="default.asp" >
更新顯示< /a >< /b >
< h5 >發言:
< input type="text" name="txttalk" size="70" >< br >
< h5 >您的姓名:
< input type="text" name="txtname" length="20"
value=< %=session("ssname")% > >
< input type="submit" name="cmdpost" default="true" value="發送" >
< /form >< /center >< /body >< /html >
---- 以上代碼在NT4.0、IIS4.0、IE4.0中和Pwin98、PWS、IE4.0中分別運行通過。