Changeset a845faf in network-game for client


Ignore:
Timestamp:
Nov 23, 2012, 6:12:17 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
d87708d
Parents:
aee34b9
Message:

Added a compiler header to determine whether a windows or linux compiler is being used

Location:
client/Client
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • client/Client/Client.vcxproj

    raee34b9 ra845faf  
    6262  </ItemDefinitionGroup>
    6363  <ItemGroup>
     64    <ClCompile Include="..\..\common\message.cpp" />
    6465    <ClCompile Include="main.cpp" />
    6566  </ItemGroup>
    6667  <ItemGroup>
     68    <ClInclude Include="..\..\common\compiler.h" />
    6769    <ClInclude Include="..\..\common\message.h" />
    6870  </ItemGroup>
  • client/Client/Client.vcxproj.filters

    raee34b9 ra845faf  
    2222      <Filter>Source Files</Filter>
    2323    </ClCompile>
     24    <ClCompile Include="..\..\common\message.cpp">
     25      <Filter>Source Files\common</Filter>
     26    </ClCompile>
    2427  </ItemGroup>
    2528  <ItemGroup>
     
    2730      <Filter>Source Files\common</Filter>
    2831    </ClInclude>
     32    <ClInclude Include="..\..\common\compiler.h">
     33      <Filter>Source Files\common</Filter>
     34    </ClInclude>
    2935  </ItemGroup>
    3036</Project>
  • client/Client/main.cpp

    raee34b9 ra845faf  
    1 /* UDP client in the internet domain */
     1#include "../../common/compiler.h"
     2
    23#include <sys/types.h>
    34
    4 #include <winsock2.h>
    5 #include <WS2tcpip.h>
     5#ifdef WINDOWS
     6        #include <winsock2.h>
     7        #include <WS2tcpip.h>
     8#endif
    69
    710#include <stdio.h>
    811#include <stdlib.h>
    9 #include <string.h>
     12#include <string>
    1013
    1114#include <iostream>
     
    1518#include "../../common/message.h"
    1619
    17 #pragma comment(lib, "ws2_32.lib")
     20#ifdef WINDOWS
     21        #pragma comment(lib, "ws2_32.lib")
     22#endif
    1823
    1924using namespace std;
    2025
    2126void 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 }
    3227
    3328int main(int argc, char *argv[])
     
    3732        struct hostent *hp;
    3833        char buffer[256];
     34        NETWORK_MSG msgTo, msgFrom;
    3935
    4036        if (argc != 3) {
     
    6864        server.sin_port = htons(atoi(argv[2]));
    6965        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);
    7268
    73         socklen_t fromlen = sizeof(server);
     69        n=sendMessage(&msgTo, sock, &server);
     70        if (n < 0)
     71                error("sendMessage");
    7472
    75         n=sendto(sock,buffer, strlen(buffer), 0, (const struct sockaddr *)&server, fromlen);
     73        n = receiveMessage(&msgFrom, sock, &from);
    7674        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");
    8276       
    83         buffer[n] = '\0';
    8477        cout << "Got an ack: " << endl;
    85         cout << buffer << endl;
     78        cout << msgFrom.buffer << endl;
    8679
    8780        closesocket(sock);
     
    9285}
    9386
    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
    10688void error(const char *msg)
    10789{
Note: See TracChangeset for help on using the changeset viewer.