Got a connection between the server folder and the client.

This commit is contained in:
jsrobson10 2019-03-25 09:18:06 +11:00
parent d77dc480d2
commit ba2fa07e19
15 changed files with 81 additions and 34 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
# Don't incude these binary files
*.out
*.o
*.exe

View File

@ -1,2 +1,5 @@
# online-game # online-game
An online game created with C++ An online game created with C++
# Port
This game uses port 34698

17
client/Makefile Normal file
View File

@ -0,0 +1,17 @@
all: connections.o main.o mainloop-api.o socket.o
g++ connections.o main.o mainloop-api.o socket.o
connections.o: connections.cpp
g++ -c connections.cpp
main.o: main.cpp
g++ -c main.cpp
mainloop-api.o: lib/mainloop-api/mainloop-api.cpp
g++ -c lib/mainloop-api/mainloop-api.cpp -o mainloop-api.o
socket.o: lib/socket/socket.cpp
g++ -c lib/socket/socket.cpp -o socket.o
clean:
rm *.o

View File

@ -1,8 +1,20 @@
#include "lib/socket.h" #include "lib/socket/socket.h"
#include <cstdlib>
client_tcp *client; client_tcp *client;
int connections_init() void connections_init(int argc, char const* argv[])
{ {
client = new client_tcp() // Get the port
int port = PORT_DEFAULT;
// Did the user specify a port
if(argc > 2)
{
// Set the port to the specified one
port = atoi(argv[2]);
}
// Create a client
client = new client_tcp(argv[1], port);
} }

View File

@ -0,0 +1 @@
void connections_init(int argc, char const* argv[]);

View File

@ -2,6 +2,8 @@
int main(int argc, char const *argv[]) int main(int argc, char const *argv[])
{ {
// Initialise the connections
connections_init(argc, argv);
return 0; return 0;
} }

1
lib/mainloop-api Submodule

@ -0,0 +1 @@
Subproject commit c7924fc3f4cef1e42b27c683d1413aed5d684374

View File

@ -2,6 +2,8 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#define PORT_DEFAULT 34698;
class client_tcp class client_tcp
{ {
public: public:

Binary file not shown.

View File

@ -1,13 +0,0 @@
#include <iostream>
#include <unistd.h>
#include "socket.h"
int main(int argc, char const *argv[])
{
client_tcp client("localhost", 12345);
std::cout << "Status: " << client.status << '\n';
std::cout << client.recv(2) << '\n';
return 0;
}

Binary file not shown.

View File

@ -1,16 +0,0 @@
#include <iostream>
#include "socket.h"
int main(int argc, char const *argv[])
{
server_tcp server(12345);
while(1)
{
client_tcp client = server.cliaccept();
client.send("hi", 2);
}
return 0;
}

17
server/Makefile Normal file
View File

@ -0,0 +1,17 @@
all: connections.o main.o mainloop-api.o socket.o
g++ connections.o main.o mainloop-api.o socket.o
connections.o: connections.cpp
g++ -c connections.cpp
main.o: main.cpp
g++ -c main.cpp
mainloop-api.o: lib/mainloop-api/mainloop-api.cpp
g++ -c lib/mainloop-api/mainloop-api.cpp -o mainloop-api.o
socket.o: lib/socket/socket.cpp
g++ -c lib/socket/socket.cpp -o socket.o
clean:
rm *.o

View File

@ -1,3 +1,20 @@
#include "lib/socket.h" #include "lib/socket/socket.h"
#include <cstdlib>
server_tcp server; server_tcp *server;
void connections_init(int argc, char const *argv[])
{
// Get the port
int port = PORT_DEFAULT;
// Did the user specify a port
if(argc > 1)
{
// Set the port to the specified one
port = atoi(argv[1]);
}
// Start the server
server = new server_tcp(port);
}