下载本文示例代码
天极IT资讯短信服务 电脑小技巧
function check4() { if (dn.mobile.value.length!=11) { alert("手机号码不正确!"); dn.mobile.focus(); return false; } return true; }
资费:包月5元手机:
介绍:细处着手,巧处用功。高手和菜鸟之间的差别就是:高手什么都知道,菜鸟知道一些。电脑小技巧收集最新奇招高招,让你轻松踏上高手之路。(首月免费) 网络编程已经成为一种时髦,以TCP/IP协议的网络更为流行.自己编一个服务器与客户机互相传送消息的程序,以便增加自己网络编程的经验.下面我就介绍一下我编的程序. 首先介绍服务器程序: 1.创建一个名为"server"的项目,单文档界面. 2.在serverview.h中加入代码:
#include "winsock.h" 添加变量:
CSize sizeTotal;//控制滚动条int count;//信息条数CString m_data[1000];//信息存放char Hostname[260];char Hostaddress[20];//主机IP地址SOCKET m_sock;HANDLE m_hListenThread;//线程BOOL m_bInitialized;//是否初始化WSADATA WSAData;BOOL flag;SOCKADDR_IN saClnt;int saClntLen;BOOL Isconnect;//是否连接 3.在serverview.cpp中重载CServerView()构造器,创建并绑定嵌套字:
CServerView::CServerView(){ // TODO: add construction code hereIsconnect=FALSE;flag=FALSE;sizeTotal.cy=350;sizeTotal.cx=300;m_hListenThread;count=5;int status;WSADATA wsaData;m_data[0]="initializing Windows Sockets DLL....";if((status=WSAStartup(0x0101,&wsaData))==0){ m_data[0] ="Succeeded";m_bInitialized=TRUE;}else{ m_bInitialized=FALSE;}m_sock=socket(AF_INET,SOCK_DGRAM,0);m_data[1]="Creating socket....";if(m_sock==INVALID_SOCKET){ m_data[1] ="Failed";}m_data[1] ="Succeeded";m_data[2]="Binding socket....";sockaddr_in sa;sa.sin_family=AF_INET;sa.sin_addr.S_un.S_addr=htonl(INADDR_ANY);sa.sin_port=htons(5050);if(bind(m_sock,(PSOCKADDR)&sa,sizeof(sa))==SOCKET_ERROR){ m_data[2] ="Failed";closesocket(m_sock);}m_data[2] ="Succeeded";m_data[3]="Creating listener thread....";unsigned long idThread;m_hListenThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Listen,(void *)this,0,&idThread);if(m_hListenThread){ m_data[3] ="Succeeded";m_data[4] ="Listening....";}elsem_data[4] ="Failed";} 4.在析构函数中完成必需的清除操作:
CServerView::~CServerView(){ if(m_bInitialized)WSACleanup();closesocket(m_sock);if(m_hListenThread)::TerminateThread(m_hListenThread,0);} 5.定义接收和处理消息的线程:
long WINAPI Listen(CServerView *pView){ char msg[2000]="";int nchar;SOCKADDR_IN saClnt;int saClntLen;while(1){ saClntLen=sizeof(saClnt);nchar=recvfrom(pView- >m_sock,msg,1024,0,(PSOCKADDR)&saClnt,&saClntLen);if(nchar< 0){ pView- >m_data[pView- >count ] ="Error in recvfrom";pView- >InvalidateRect(NULL);}else{ switch(msg[0]){case ’A’: wsprintf(msg,"A:Client from %s attached",inet_ntoa(saClnt.sin_addr));pView- >m_data[pView- >count ]=msg;pView- >flag=TRUE;pView- >InvalidateRect(NULL);pView- >Isconnect=TRUE;pView- >saClnt=saClnt;pView- >saClntLen=saClntLen;sendto(pView- >m_sock,msg,1024,0,(PSOCKADDR)&saClnt,saClntLen);break;case ’D’:wsprintf(msg,"D: Client form %s detached",inet_ntoa(saClnt.sin_addr));pView- >m_data[pView- >count ]=msg;pView- >flag=TRUE;pView- >InvalidateRect(NULL);pView- >Isconnect=FALSE;sendto(pView- >m_sock,msg,1024,0,(PSOCKADDR)&saClnt,saClntLen);break;case ’R’:saClntLen=sizeof(saClnt);pView- >m_data[pView->count ]=msg;pView- >flag=TRUE;pView- >InvalidateRect(NULL);break;default:break;}}}return(0);}共3页。 1 2 3 :
天极IT资讯短信服务 电脑小技巧
function check4() { if (dn.mobile.value.length!=11) { alert("手机号码不正确!"); dn.mobile.focus(); return false; } return true; }
资费:包月5元手机:
介绍:细处着手,巧处用功。高手和菜鸟之间的差别就是:高手什么都知道,菜鸟知道一些。电脑小技巧收集最新奇招高招,让你轻松踏上高手之路。(首月免费) 网络编程已经成为一种时髦,以TCP/IP协议的网络更为流行.自己编一个服务器与客户机互相传送消息的程序,以便增加自己网络编程的经验.下面我就介绍一下我编的程序. 首先介绍服务器程序: 1.创建一个名为"server"的项目,单文档界面. 2.在serverview.h中加入代码:
#include "winsock.h" 添加变量:
CSize sizeTotal;//控制滚动条int count;//信息条数CString m_data[1000];//信息存放char Hostname[260];char Hostaddress[20];//主机IP地址SOCKET m_sock;HANDLE m_hListenThread;//线程BOOL m_bInitialized;//是否初始化WSADATA WSAData;BOOL flag;SOCKADDR_IN saClnt;int saClntLen;BOOL Isconnect;//是否连接 3.在serverview.cpp中重载CServerView()构造器,创建并绑定嵌套字:
CServerView::CServerView(){ // TODO: add construction code hereIsconnect=FALSE;flag=FALSE;sizeTotal.cy=350;sizeTotal.cx=300;m_hListenThread;count=5;int status;WSADATA wsaData;m_data[0]="initializing Windows Sockets DLL....";if((status=WSAStartup(0x0101,&wsaData))==0){ m_data[0] ="Succeeded";m_bInitialized=TRUE;}else{ m_bInitialized=FALSE;}m_sock=socket(AF_INET,SOCK_DGRAM,0);m_data[1]="Creating socket....";if(m_sock==INVALID_SOCKET){ m_data[1] ="Failed";}m_data[1] ="Succeeded";m_data[2]="Binding socket....";sockaddr_in sa;sa.sin_family=AF_INET;sa.sin_addr.S_un.S_addr=htonl(INADDR_ANY);sa.sin_port=htons(5050);if(bind(m_sock,(PSOCKADDR)&sa,sizeof(sa))==SOCKET_ERROR){ m_data[2] ="Failed";closesocket(m_sock);}m_data[2] ="Succeeded";m_data[3]="Creating listener thread....";unsigned long idThread;m_hListenThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Listen,(void *)this,0,&idThread);if(m_hListenThread){ m_data[3] ="Succeeded";m_data[4] ="Listening....";}elsem_data[4] ="Failed";} 4.在析构函数中完成必需的清除操作:
CServerView::~CServerView(){ if(m_bInitialized)WSACleanup();closesocket(m_sock);if(m_hListenThread)::TerminateThread(m_hListenThread,0);} 5.定义接收和处理消息的线程:
long WINAPI Listen(CServerView *pView){ char msg[2000]="";int nchar;SOCKADDR_IN saClnt;int saClntLen;while(1){ saClntLen=sizeof(saClnt);nchar=recvfrom(pView- >m_sock,msg,1024,0,(PSOCKADDR)&saClnt,&saClntLen);if(nchar< 0){ pView- >m_data[pView- >count ] ="Error in recvfrom";pView- >InvalidateRect(NULL);}else{ switch(msg[0]){case ’A’: wsprintf(msg,"A:Client from %s attached",inet_ntoa(saClnt.sin_addr));pView- >m_data[pView- >count ]=msg;pView- >flag=TRUE;pView- >InvalidateRect(NULL);pView- >Isconnect=TRUE;pView- >saClnt=saClnt;pView- >saClntLen=saClntLen;sendto(pView- >m_sock,msg,1024,0,(PSOCKADDR)&saClnt,saClntLen);break;case ’D’:wsprintf(msg,"D: Client form %s detached",inet_ntoa(saClnt.sin_addr));pView- >m_data[pView- >count ]=msg;pView- >flag=TRUE;pView- >InvalidateRect(NULL);pView- >Isconnect=FALSE;sendto(pView- >m_sock,msg,1024,0,(PSOCKADDR)&saClnt,saClntLen);break;case ’R’:saClntLen=sizeof(saClnt);pView- >m_data[pView->count ]=msg;pView- >flag=TRUE;pView- >InvalidateRect(NULL);break;default:break;}}}return(0);}共3页。 1 2 3 :
下载本文示例代码
VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序VC6.0编写C/S消息传送程序