Winsock Server Client Example

0

Good morning, As I work in the uni, they have sent us to do a program with a server and a client. But for this we have been told that first we have to make an example of server and client work. They have given us the example like this, with these 2 codes.

Server: link

Client: link

What I have done has been to open a project and I have put each code (the one of the client and the server) in a file: server.cpp and client.cpp

And after fixing a problem with the headers I got stuck with these 2 errors:

  

Severity Code Description Project File Line Suppression State   Error LNK2005 _main already defined in   client.obj BAAER2 D: \ DDocuments \ BAAER2 \ BAAER2 \ BAAER2 \ server.obj 1

and

  

Severity Code Description Project File Line Suppression State   Error LNK1169 one or more multiply defined symbols   found BAAER2 D: \ DDocuments \ BAAER2 \ BAAER2 \ Debug \ BAAER2.exe 1

The first one I think it has is that I have 2 files with main but I'm not sure how to fix it.

PS: The teacher said that you had to add or pass as argument localhost (127.0.0.1), with right click properties ... but I do not remember much more, do you also know this?

    
asked by 19mikel95 26.03.2016 в 13:49
source

1 answer

0

Create two different projects, one called, client and the other server. Put each of the sources in one of these different projects. Both projects must link the ws_32.lib library that provides the winsock2 methods.

Then you compile the projects and run the server first.

Finally, you run the client from the command line like this: (you must find where the compiler left the .exe file)

C:\Path\al\cliente> cliente.exe 127.0.0.1

With that it should work.

    
answered by 26.03.2016 / 16:33
source