Yeah, sure.
Here's the code for accepting a connection:
clientSocket=accept(sock,clientAddr,0); cout<<"\nConnection requested"<<endl; if(clientSocket==INVALID_SOCKET) { cout<<"Error: connection failed"<<endl; } else //Continue if socket is good { recv(sock,(char*)&id,sizeof(id),0); recv(sock,password,sizeof(password),0); cout<<"Client number "<<id<<" has connected"<<endl; cout<<"Password: "<<password<<endl;
And here's the client connecting:
//Connect to server cout<<"Logging in..."<<endl; if(connect(server,(const sockaddr*)&addr,sizeof(addr))==SOCKET_ERROR) { cout<<"Error: Could not connect to server!"<<endl; cin.ignore(1,'\n'); WSACleanup(); return 0; } //Send the id and password to server, and see if we're allowed to continue send(server,(char*)&id,sizeof(id),0); send(server,password,sizeof(password),0); cout<<"Data sent"<<endl;
I tried zeroing out the variables before they're recieved, and the number changed from 4007136 to 0, and the password changed to "" every time.