http://lacewing-project.org/
I'd start with this simple little library. I can provide examples if the documentation isn't self explanitory.
As a bare minimum, you'd need this code:
1 2 3 4 5 6 7 8 9 10 11 12
//Server
#include "Lacewing.h"
int main()
{
Lacewing::EventPump EventPump;
Lacewing::RelayServer Server (EventPump); //RelayServer has a protocol already for you
Server.Host(6121);
EventPump.StartEventLoop();
//Done! Server will host as long as the program runs
//For special server-side behavior you need to register handlers as in the docs
}
//Client
#include "Lacewing.h"
int main()
{
Lacewing::EventPump EventPump;
Lacewing::RelayClient Self (EventPump); //RelayClient to connect to RelayServer
Self.Connect("127.server.ip.0", 6121);
//you need to register handlers to further initiate the connection
//(setting name, joining channels, etc.)
do
{
EventPump.Tick(); //rarely returns an error, see documentation
//Game Code
}while(/*game loop condition*/);
}
Thanks LB. However, i need to use the actual communicating codes for my assignment.
Anyway I managed to setup the server and client socket. Now i need to move on to the communicating part. what are the codes for server and client to communicate?
What do you mean "codes"? If you're using Lacewing::Server and Lacewing:Client, or just Lacewing::Socket, then you have to decide on packet codes yourself.
Unless by "codes" you mean "code"? There's a big difference.
In that case, the site has documentation that explains everything in depth...
My program requires the client player to enter a target square (eg. A3) in the server's grid which is to be shot at. if a ship occupies the square, then it takes a hit, the server opponent will reply whether or not the shot hit one of its ships and type of warship will be revealed using the symbol code.
The desired output should be like this,
Client's console
Enter a square on the battle grid to bomb:
A3
Server's console
Client bombed on square - A3
A miss!
Client's console
A miss!
Pls enter another square to bomb or press V to view your battle grid: