#include<iostream>
using namespace std;
#include<winsock2.h>
#pragma comment(lib,"ws2_32.lib")
void main()
{
const int DEFAULT_PROTOCOL=0;
WSADATA ws;
int i1=WSAStartup(MAKEWORD(2,2),&ws);
//cout<<ws.wVersion<<endl
//<<WINSOCK_VERSION<<endl;
if(i1==0)
cout<<"call wsastartup successful"<<endl;
else
cout<<"err wsastartup"<<endl;
SOCKET s=socket(AF_INET,SOCK_STREAM,DEFAULT_PROTOCOL);
if(s!=INVALID_SOCKET)
cout<<"call socket fuction successful"<<endl;
else
cout<<"err in create socket"<<endl;
sockaddr_in sin;
//sin.sin_addr.s_addr=inet_addr('172.16.7.37');
//my_addr.sin_addr.s_addr = inet_addr("192.168.18.7");
sin.sin_addr.s_addr = inet_addr("172.16.7.37");
sin.sin_family=AF_INET;
sin.sin_port=htons(8402);
bind(s,(sockaddr *) &sin,sizeof(sin));
int i2=listen(s,2);
if(i2==0)
cout<<"listening..."<<endl;
else
cout<<"err listen"<<endl;
SOCKET cs=socket(AF_INET,SOCK_STREAM,0);
if(cs!=INVALID_SOCKET)
cout<<"open client socket successfull"<<endl;
else
cout<<"open client socket err"<<endl;
int i3=connect(cs,(sockaddr *) &sin,sizeof(sin));
//bind(s,(sockaddr *) &sin,sizeof(sin));
if(i3==0)
cout<<"connected to server successfull"<<endl;
else
cout<<"can not connect to server"<<endl;
//connect(s,(sockaddr *) &sin,sizeof(sin));
char datas[10]="hello";
send(s,datas,2,0);
char datat[10]="0";
int i4=recv(cs,datat,2,0);
if(i4==10){
cout<<datas<<endl;
cout<<datat<<endl;
}
else
cout<<"recv err";
int i5=closesocket(s);
//int i6=closesocket(cs);
if(i5==0)
cout<<"close server socket succ";
}
结果怎么不输出?也不退出?
发个帖子还真难~~~~我换了七八个标题都不行,分号前面的也请告诉一下,怎么加?