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,源码myeclipse下载jdk源码 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-28 20:471868人浏览
2024-12-28 20:271121人浏览
2024-12-28 20:19646人浏览
2024-12-28 19:15987人浏览
2024-12-28 19:10824人浏览
2024-12-28 18:57668人浏览
五月報稅季即將到來,財政部北區國稅局表示,今年綜合所得稅結算申報有4項新規定,另外還提供多元化繳稅方式,《台視新聞》統整今年報稅全攻略,提供讀者參考。報稅時間綜合所得稅結算申報期間自今113)年5月1
1.网络管理软件的智和信通SugarNMS网管软件2.网管软件是什么?3.什么网管软件可以对设备能够全面管控、深度管控网络管理软件的智和信通SugarNMS网管软件 SugarNMS智和网管软件是