Windows??Linux????socket???
???????????? ???????[ 2013/2/5 14:40:49 ] ????????
???????????棬??????????????????windows???????????????????????????linux???????????ping??ftp??samba??telnet??ssh?????????????????????????windows????????windows socket????linux????posix socket???????????socket??????????????????????windows??windows?????????linux??linux???????????????windows??linux???????????????????д???????socket???????linux??windows??????
????????????????????????????????????????????????socket??????????????????????????д????????????????????????????ü???????????socket??????????????????????????????????????????ü????????????????
????windows???client????
#include <stdio.h>
#include <Windows.h>
#pragma comment(lib??"ws2_32.lib")
#define PORT 4000
#define IP_ADDRESS "192.168.1.102"
int main(int argc?? char* argv[])
{
WSADATA Ws;
SOCKET CientSocket;
struct sockaddr_in ClientAddr;
int Ret = 0;
char SendBuffer[MAX_PATH];
/* Init Windows Socket */
if ( WSAStartup(MAKEWORD(2??2)?? &Ws) != 0 )
{
printf("Init Windows Socket Failed::%d
"?? GetLastError());
return -1;
}
/* Create Socket */
CientSocket = socket(AF_INET?? SOCK_STREAM?? IPPROTO_TCP);
if ( CientSocket == INVALID_SOCKET )
{
printf("Create Socket Failed::%d
"?? GetLastError());
return -1;
}
ClientAddr.sin_family = AF_INET;
ClientAddr.sin_addr.s_addr = inet_addr(IP_ADDRESS);
ClientAddr.sin_port = htons(PORT);
memset(ClientAddr.sin_zero?? 0x00?? 8);
/* connect socket */
Ret = connect(CientSocket??(struct sockaddr*)&ClientAddr?? sizeof(ClientAddr));
if ( Ret == SOCKET_ERROR )
{
printf("Connect Error::%d
"?? GetLastError());
return -1;
}
else
{
printf("Connect succedded!
");
}
while (1)
{
scanf("%s"?? SendBuffer);
/* send data to server */
Ret = send(CientSocket?? SendBuffer?? (int)strlen(SendBuffer)?? 0);
if ( Ret == SOCKET_ERROR )
{
printf("Send Info Error::%d
"?? GetLastError());
break;
}
if('q' == SendBuffer[0])
{
break;
}
}
/* close socket */
closesocket(CientSocket);
WSACleanup();
return 0;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11