- Timestamp:
- Nov 23, 2012, 6:12:17 PM (12 years ago)
- Branches:
- master
- Children:
- d87708d
- Parents:
- aee34b9
- Location:
- client/Client
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/Client.vcxproj
raee34b9 ra845faf 62 62 </ItemDefinitionGroup> 63 63 <ItemGroup> 64 <ClCompile Include="..\..\common\message.cpp" /> 64 65 <ClCompile Include="main.cpp" /> 65 66 </ItemGroup> 66 67 <ItemGroup> 68 <ClInclude Include="..\..\common\compiler.h" /> 67 69 <ClInclude Include="..\..\common\message.h" /> 68 70 </ItemGroup> -
client/Client/Client.vcxproj.filters
raee34b9 ra845faf 22 22 <Filter>Source Files</Filter> 23 23 </ClCompile> 24 <ClCompile Include="..\..\common\message.cpp"> 25 <Filter>Source Files\common</Filter> 26 </ClCompile> 24 27 </ItemGroup> 25 28 <ItemGroup> … … 27 30 <Filter>Source Files\common</Filter> 28 31 </ClInclude> 32 <ClInclude Include="..\..\common\compiler.h"> 33 <Filter>Source Files\common</Filter> 34 </ClInclude> 29 35 </ItemGroup> 30 36 </Project> -
client/Client/main.cpp
raee34b9 ra845faf 1 /* UDP client in the internet domain */ 1 #include "../../common/compiler.h" 2 2 3 #include <sys/types.h> 3 4 4 #include <winsock2.h> 5 #include <WS2tcpip.h> 5 #ifdef WINDOWS 6 #include <winsock2.h> 7 #include <WS2tcpip.h> 8 #endif 6 9 7 10 #include <stdio.h> 8 11 #include <stdlib.h> 9 #include <string .h>12 #include <string> 10 13 11 14 #include <iostream> … … 15 18 #include "../../common/message.h" 16 19 17 #pragma comment(lib, "ws2_32.lib") 20 #ifdef WINDOWS 21 #pragma comment(lib, "ws2_32.lib") 22 #endif 18 23 19 24 using namespace std; 20 25 21 26 void error(const char *); 22 23 int boost_main()24 {25 using namespace boost::lambda;26 typedef istream_iterator<int> in;27 28 for_each(in(cin), in(), cout << (_1 * 3) << " " );29 30 return 0;31 }32 27 33 28 int main(int argc, char *argv[]) … … 37 32 struct hostent *hp; 38 33 char buffer[256]; 34 NETWORK_MSG msgTo, msgFrom; 39 35 40 36 if (argc != 3) { … … 68 64 server.sin_port = htons(atoi(argv[2])); 69 65 cout << "Please enter the message: "; 70 memset(buffer, 0, 256);71 fgets(buffer,255,stdin);66 cin.getline(msgTo.buffer, 256); 67 socklen_t socklen = sizeof(server); 72 68 73 socklen_t fromlen = sizeof(server); 69 n=sendMessage(&msgTo, sock, &server); 70 if (n < 0) 71 error("sendMessage"); 74 72 75 n =sendto(sock,buffer, strlen(buffer), 0, (const struct sockaddr *)&server, fromlen);73 n = receiveMessage(&msgFrom, sock, &from); 76 74 if (n < 0) 77 error("Sendto"); 78 79 n = recvfrom(sock, buffer, 256, 0, (struct sockaddr *)&from, &fromlen); 80 if (n < 0) 81 error("recvfrom"); 75 error("receiveMessage"); 82 76 83 buffer[n] = '\0';84 77 cout << "Got an ack: " << endl; 85 cout << buffer << endl;78 cout << msgFrom.buffer << endl; 86 79 87 80 closesocket(sock); … … 92 85 } 93 86 94 /* 95 int sendMessage(short type, string contents, int sock, struct sockaddr_in *dest) 96 { 97 NETWORK_MSG msg; 98 99 msg.type = type; 100 strcpy(msg.buffer, contents.c_str()); 101 102 return sendto(sock, (char*)&msg, sizeof(NETWORK_MSG), 0, (struct sockaddr *)dest, sizeof(dest)); 103 } 104 */ 105 87 // need to make a function like this that works on windows 106 88 void error(const char *msg) 107 89 {
Note:
See TracChangeset
for help on using the changeset viewer.