1.vc怎么获得时间?
2.å¦ä½ç¼åç®åçsocketç½ç»ç¨åº å¦ä½ç¼ååºäºTCPåè®®çç½ç»ç¨åº
vc怎么获得时间?
void CUdp2Dlg::OnUDPClient()
{
//建立客户端套接字,源码并发送,源码aspx项目源码发布目的源码ios微博源码获取网络时间
CString strsend,strrece;
strsend="0 1 3 0 0 0 0 0 0 0 0 0 0";
m_sockrecv.Create(,SOCK_DGRAM,".6..");
m_sockrecv.Bind(,".6..");
m_sockrecv.SendTo(strsend,,,".6..",0);
SetTimer(1,,NULL);
}
void CUdp2Dlg::OnTimer(UINT nIDEvent)
{
//建立定时器,接受时间
char strrece[];
UINT uport=;
CString strip=".6..";
int irecv=m_sockrecv.ReceiveFrom(strrece,源码android 截屏源码,strip,uport,0);
//strrece[irecv]='\0';
if(irecv!=SOCKET_ERROR)
{
strrece[irecv]=NULL;
m_editrecv=strrece;
UpdateData(FALSE);
}
CDialog::OnTimer(nIDEvent);
}
å¦ä½ç¼åç®åçsocketç½ç»ç¨åº å¦ä½ç¼ååºäºTCPåè®®çç½ç»ç¨åº
ããä¸é¢æ¯ä¸ªäººç¨äºä¸ä¸ªåéå·¦å³çæ¶é´ç¼åçç¨åºï¼å¨è¿ç¼åè¿ç¨ä¸ï¼é常éè¦çä¸ç¹å°±æ¯ï¼ è¦ç解 tcpåè®®ç¼åç¨åºçåçï¼å³ç¼åæå¡å¨ç«¯çè¿ç¨ï¼ä»¥åç¼å客æ·ç«¯çè¿ç¨ã åªè¦ææ¡è¿ä¸¤ç¹å°±å¯ä»¥å¾å®¹æç¼ååºæ¥äºï¼ä½æ¯è¦å¿«éç¼ååºè¿ä¸ªç¨åºï¼é£ä¹VC6.0å¼åå·¥å ·éï¼æ好è¦å®è£ ä¸ä¸ªçªèæ件ï¼è¿ä¸ªæ件å¯ä»¥å¿«éæé«ä½ çç¼åç¨åºçæçï¼è¿æä¹è¦å®è£ msdn ææ¡£ï¼è¿æ ·å¨ç¼åè¿ç¨ä¸ï¼éå°å¯¹æ个å½æ°çåæ°æ³ä¸å ¨çæ¶åï¼ä½¿ç¨msdnå°±è½å¿«éå¸®ä½ åå¿äºã åµåµï¼å¦æä½ é£ä¸å¤©å»é¢è¯ä¸å®¶çé¼çå ¬å¸çåï¼å¾æå¯è½å°±æ¯ å¨ç¬è¯å®æä¹åï¼å°±è¦è¿è¡æºè¯äºï¼è¿å°±å®å ¨èæ¥åºä½ ççæ£ç¼ç¨æ°´å¹³äºã è½å¨æçæ¶é´éå®æä¸ä¸ªsocketç½ç»ç¨åºï¼é£ä¹å°±å¯ä»¥ä»¤é¢è¯å®æå°é常满æäºã ä¸è¿ï¼è¿ä¸ªç¨åºï¼è¿æ²¡æè¿æ¥æ°æ®åºï¼ä»¥åå继ç»æäºã
ããå¦æä½ å»é¢è¯ æ·±å³ç§æå é£å®¶ ä¼æè¾¾ éå¢å ¬å¸ç软件工ç¨å¸çåï¼é£ä¹æºè¯é¢ç®å°±æ¯è¿ä¸ªã å½æ¶æå»é¢è¯ï¼é¦å è¿è¡ç¬è¯ï¼é¢è¯å®å¯¹æç¬è¯æ绩æ¯è¾æ»¡æï¼æ以就å«æçä¸æ¥åé¡¿é¥ï¼ä¸åè¿è¡æºè¯ã å½æ¶æåºèå²ä½æ¯Linuxç³»ç»å·¥ç¨å¸Cè¯è¨ï¼ å¯æ¯ç¬è¯é¢ç®ï¼ä¸ä½èæ ¸Cï¼è¿èæ ¸C++ï¼JavaScriptï¼htmlã ææè§å¥½å¥æªï¼å¿éæ³ï¼å¥½åææ¯åºèVC++å¼åé£ä¸ªå²ä½äºã äºæ¯æçå°ä¸åï¼ä»æ¿æ¥æºè¯é¢ç®ä¹æ¶ï¼æçæ£æç½ï¼æç¶æ¯ä»è¦å®ææä»äºVC++å¼åäºï¼é¢ç®å°±æ¯ï¼ç¼ååºäºTCP/IPåè®®ç½ç»ç¨åºï¼å¹¶å®ç°ç®åçè天ç¨åºï¼èä¸è¦è¿æ¥æ°æ®åºã å½æ¶æå失æäºã äºæ¯æå°±æåºï¼æä¸æ³åè¿ä¸ªé¢ç®ï¼å 为ææ¯æ³åºèLinuxç³»ç»Cè¯è¨å¼åçã å°±è¿æ ·å¤±æçèµ°äºã
ããä¸é¢æ¯ä¸ªäººå®å ¨è½è¿è¡ç代ç ï¼
ããæå¡å¨ç«¯æºç ï¼
ãã#include<stdio.h>
#include <Winsock2.h>
#pragma comment (lib,"ws2_.lib")
ããint main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return 0;
}
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
WSACleanup( );
return 0;
}
ããSOCKET socketServer=socket(AF_INET,SOCK_STREAM,0);
ããSOCKADDR_IN addrServer;
ããaddrServer.sin_family=AF_INET;
ããaddrServer.sin_addr.S_un.S_addr=htonl(INADDR_ANY);
ããaddrServer.sin_port=htons();
ããbind(socketServer, (struct sockaddr *)&addrServer, sizeof(struct sockaddr));
ããlisten(socketServer, 5);
ããSOCKADDR_IN addrClient;
ããint addrLen=sizeof(SOCKADDR_IN);
ããchar sendBuf[];
ããchar recvBuf[];
ããint i=1;
while(1)
{
printf("æå¡å¨ç«¯çå¾ ç¬¬%d个客æ·ç«¯è¿æ¥è¯·æ±...\n", i++);
ããSOCKET newsocketServer=accept(socketServer,(struct sockaddr *)&addrClient, &addrLen);
ããif(newsocketServer!=INVALID_SOCKET)
{
printf("æå¡å¨ç«¯ä¸å®¢æ·ç«¯è¿æ¥æå...\n");
}
ããmemset(sendBuf,0,);
ããsprintf(sendBuf,"Welcome you to come here");
ããsend(newsocketServer, sendBuf, strlen(sendBuf)+1,0);
ããmemset(recvBuf,0,);
ããrecv(newsocketServer,recvBuf,,0);
ããprintf("æå¡å¨ç«¯æ¶å°ä¿¡æ¯:%s\n",recvBuf);
ããclosesocket(newsocketServer);
}
ããWSACleanup();
ããreturn 0;
}
ããæ¤æç« æ¥èªäºä¸ªäººåå®¢ï¼ é¿æµªå客 /wenxianliang@/
ãã客æ·ç«¯æºç ï¼
ãã#include<stdio.h>
#include <Winsock2.h>
#pragma comment (lib,"ws2_.lib")
ããint main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return 0;
}
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
WSACleanup( );
return 0;
}
SOCKET socketClient=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrServer;
addrServer.sin_family=AF_INET;
addrServer.sin_addr.S_un.S_addr=inet_addr(".0.0.1");
addrServer.sin_port=htons();
char sendBuf[];
char recvBuf[];
ããprintf("客æ·ç«¯åæå¡å¨ç«¯è¿æ¥è¯·æ±...\n");
ããint Isconnect=connect(socketClient, (struct sockaddr *)&addrServer, sizeof(struct sockaddr));
ããif(Isconnect!=0)
{
printf("客æ·ç«¯æ æ³è¿æ¥æå¡å¨ç«¯...\n");
ããreturn 0;
}
ããprintf("客æ·ç«¯å·²æåè¿æ¥æå¡å¨ç«¯...\n");
ããmemset(recvBuf,0,);
recv(socketClient,recvBuf,,0);
ããprintf("客æ·ç«¯æ¶å°ä¿¡æ¯:%s\n",recvBuf);
ããmemset(sendBuf,0,);
sprintf(sendBuf,"Hello , I am Mr Wen !");
send(socketClient, sendBuf, strlen(sendBuf)+1,0);
closesocket(socketClient);
WSACleanup();
return 0;
}