Got a connection between the server folder and the client.
This commit is contained in:
parent
d77dc480d2
commit
ba2fa07e19
|
@ -0,0 +1,4 @@
|
|||
# Don't incude these binary files
|
||||
*.out
|
||||
*.o
|
||||
*.exe
|
|
@ -1,2 +1,5 @@
|
|||
# online-game
|
||||
An online game created with C++
|
||||
|
||||
# Port
|
||||
This game uses port 34698
|
||||
|
|
|
@ -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
|
|
@ -1,8 +1,20 @@
|
|||
#include "lib/socket.h"
|
||||
#include "lib/socket/socket.h"
|
||||
#include <cstdlib>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
void connections_init(int argc, char const* argv[]);
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// Initialise the connections
|
||||
connections_init(argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit c7924fc3f4cef1e42b27c683d1413aed5d684374
|
|
@ -2,6 +2,8 @@
|
|||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define PORT_DEFAULT 34698;
|
||||
|
||||
class client_tcp
|
||||
{
|
||||
public:
|
Binary file not shown.
|
@ -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.
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue