1.linuxä¸çç¨åºå¦ä½å¨windowsä¸è¿è¡
linuxä¸çç¨åºå¦ä½å¨windowsä¸è¿è¡
æ¬è´¨åºå«æ¯è¿æ ·çï¼linuxä¸ç¨çæ¯ä¼¯å å©socketï¼windowsåºä¸ç¨çWinSocket.
两è å ¶å®æ¯å¤§åå°å¼çï¼ä¸åçå°æ¹å¨ä»¥ä¸å ç¹ï¼
1 头æ件ä¸åï¼å¨linuxä¸ç¨å°çå ³é®å¤´æ件<sys/socket.h>
windowsä¸ç¨å°çæ¯ <Winsock2.h>
2 socketçåå§åä¸ä¸æ ·ï¼å¨windowsä¸è¦æä¸ä¸ªWSAStartupï¼èlinux ä¸æ²¡æã
3 å ·ä½çç»èä¸ä¸æ ·ï¼linuxä¸çcåwindowsä¸çcçä¸äºè¯æ³æäºåºå ¥ï¼ä½ èªå·±æ¾æ¾ã
ä¸é¢ææwindowsä¸çsocketé讯çæåºæ¬çç»æç»ä½ ï¼ä½ å¯¹ç §çä¿®æ¹å°±å¯ä»¥äºï¼ä¸ä¸çç¨åºæè°è¯äºä¸ä¸ï¼ç¼è¯è¿äºã
客æ·ç«¯
#include <Winsock2.h>
#include <stdio.h>
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1,源码直播视频源码教程 1 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return;
}
if ( LOBYTE( wsaData.wVersion ) != 1 ||
HIBYTE( wsaData.wVersion ) != 1 ) {
WSACleanup( );
return;
}
SOCKET sockClient=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr=inet_addr(".0.0.1");
addrSrv.sin_family=AF_INET;
addrSrv.sin_port=htons();
connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
char recvBuf[];
recv(sockClient,recvBuf,,0);
printf("%s\n",recvBuf);
send(sockClient,"This is lisi",strlen("This is lisi")+1,0);
closesocket(sockClient);
WSACleanup();
}
æå¡å¨ç«¯
#include <Winsock2.h>
#include <stdio.h>
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return;
}
if ( LOBYTE( wsaData.wVersion ) != 1 ||
HIBYTE( wsaData.wVersion ) != 1 ) {
WSACleanup( );
return;
}
SOCKET sockSrv=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr=htonl(INADDR_ANY);
addrSrv.sin_family=AF_INET;
addrSrv.sin_port=htons();
bind(sockSrv,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
listen(sockSrv,5);
SOCKADDR_IN addrClient;
int len=sizeof(SOCKADDR);
while(1)
{
SOCKET sockConn=accept(sockSrv,(SOCKADDR*)&addrClient,&len);
char sendBuf[];
sprintf(sendBuf,"æ¥èªæå¡å¨ç«¯",
inet_ntoa(addrClient.sin_addr));
send(sockConn,sendBuf,strlen(sendBuf)+1,0);
char recvBuf[];
recv(sockConn,recvBuf,,0);
printf("%s\n",recvBuf);
closesocket(sockConn);
}
}
2024-12-29 16:24896人浏览
2024-12-29 15:242656人浏览
2024-12-29 15:131389人浏览
2024-12-29 14:07322人浏览
2024-12-29 14:062489人浏览
2024-12-29 13:49816人浏览
穀雨,所謂播種完成,幼穗需要較多雨水滋潤的日子,空氣中總瀰漫著水氣,讓本來體質就多濕的人們更難以排出體內的濕氣。跟濕相關的症狀諸如腦袋昏昏沈沈、疲倦、代謝下降、大便軟黏也都跑了出來。飲食這樣吃有效改善
1.天津滨海新区到张家口客车天津滨海新区到张家口客车 西直门汽车站已经搬迁注:所有业务六里桥汽车客运站) 长途汽车站路线查询 BR />六里桥长途巴士总站 咨询电话:, 地