diff --git a/TestClientConnection/TestClientConnection.cpp b/TestClientConnection/TestClientConnection.cpp index 2401cf6..b22cd32 100644 --- a/TestClientConnection/TestClientConnection.cpp +++ b/TestClientConnection/TestClientConnection.cpp @@ -1,9 +1,22 @@ #include #include #include +#include #pragma comment(lib, "Ws2_32.lib") +struct DataIn +{ + float AccX, AccY, AccZ; + float GyrX, GyrY, GyrZ; + float PosX, PosY, LaserRange; +} dataIn; + +struct DataOut +{ + float MotorUL, MotorUR, MotorDL, MotorDR; +} dataOut; + int main() { WSAData wsaData; @@ -16,16 +29,36 @@ int main() } SOCKADDR_IN addr; - addr.sin_family = AF_INET; - addr.sin_port = htons(1001); + int sizeofaddr = sizeof(addr); - // Use inet_pton instead of inet_addr - if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) <= 0) + inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr); + addr.sin_port = htons(1001); + addr.sin_family = AF_INET; + + SOCKET Connection = socket(AF_INET, SOCK_STREAM, NULL); + if (connect(Connection, (SOCKADDR*)&addr, sizeof(addr)) != 0) { - std::cout << "Error converting IP address\n"; - exit(1); + std::cout << "Error: failed connect to server \n"; + return 1; } + dataOut.MotorUL = 10; + dataOut.MotorUR = 10; + dataOut.MotorDL = 10; + dataOut.MotorDR = 10; + + while (1) + { + send(Connection, (char*)&(dataOut), sizeof(dataOut), 0); + recv(Connection, (char*)&(dataIn), sizeof(dataIn), 0); + //std::cout << dataIn.GyrX << " " << dataIn.GyrY << " " << dataIn.GyrZ << std::endl; + //std::cout << dataIn.PosX << " " << dataIn.PosY << " " << dataIn.LaserRange << std::endl; + //std::cout << dataIn.AccX << " " << dataIn.AccY << " " << dataIn.AccZ << std::endl; + std::cout << dataIn.LaserRange << std::endl; + std::cout << "-----------------------------------------------------------" << std::endl; + //std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + system("pause"); - std::cout << "Hello World!\n"; }