//server端
#include
#include
void main()
if ( lobyte( wsadata.wversion ) != 1 ||
hibyte( wsadata.wversion ) != 1 )
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(6000);
bind(socksrv,(sockaddr*)&addrsrv,sizeof(sockaddr));
listen(socksrv,5);
sockaddr_in addrclient;
int len=sizeof(sockaddr);
while(1) }
//client端
#include
#include
void main()
if ( lobyte( wsadata.wversion ) != 1 ||
hibyte( wsadata.wversion ) != 1 )
socket sockclient=socket(af_inet,sock_stream,0);
sockaddr_in addrsrv;
addrsrv.sin_addr.s_un.s_addr=inet_addr("127.0.0.1");
addrsrv.sin_family=af_inet;
addrsrv.sin_port=htons(6000);
connect(sockclient,(sockaddr*)&addrsrv,sizeof(sockaddr));
char recvbuf[100];
recv(sockclient,recvbuf,100,0);
printf("%s/n",recvbuf);
send(sockclient,"this is lisi",strlen("this is lisi")+1,0);
closesocket(sockclient);
wsacleanup();
}
socket檔案傳送
include include pragma comment lib,ws2 32.lib define ipaddr 172.26.145.2 define port 3574 class socket socket bool windowinit else sock stream 提供有序的 可...
socket實現類群聊功能
使用socket做了乙個類似群聊功能的demo,來記錄這兩天學習socket的成果。在實現功能之前先看下sockect通訊的基本流程 socket服務端 1.socket 建立套接字 3.listen 監聽套接字,準備接受客戶請求 4.accept 接收客戶端請求,返回乙個對應此連線新套接字 5.用...
C 郵件傳送 實現類
using system using system.collections.generic using system.configuration using system.io using system.linq using system.net.mail using system.net.mime...