Changed the naming convention for public member variables/functions and free functions (using lowerCase instead of UpperCase)
This commit is contained in:
parent
ff5b69d312
commit
14ac411542
200 changed files with 4302 additions and 4320 deletions
|
@ -6,10 +6,10 @@
|
|||
#include <cstdlib>
|
||||
|
||||
|
||||
void RunTcpServer(unsigned short Port);
|
||||
void RunTcpClient(unsigned short Port);
|
||||
void RunUdpServer(unsigned short Port);
|
||||
void RunUdpClient(unsigned short Port);
|
||||
void runTcpServer(unsigned short port);
|
||||
void runTcpClient(unsigned short port);
|
||||
void runUdpServer(unsigned short port);
|
||||
void runUdpClient(unsigned short port);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -37,17 +37,17 @@ int main()
|
|||
{
|
||||
// Test the TCP protocol
|
||||
if (who == 's')
|
||||
RunTcpServer(port);
|
||||
runTcpServer(port);
|
||||
else
|
||||
RunTcpClient(port);
|
||||
runTcpClient(port);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Test the unconnected UDP protocol
|
||||
if (who == 's')
|
||||
RunUdpServer(port);
|
||||
runUdpServer(port);
|
||||
else
|
||||
RunUdpClient(port);
|
||||
runUdpClient(port);
|
||||
}
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
|
|
|
@ -11,32 +11,32 @@
|
|||
/// send a message and wait for the answer.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void RunTcpServer(unsigned short port)
|
||||
void runTcpServer(unsigned short port)
|
||||
{
|
||||
// Create a server socket to accept new connections
|
||||
sf::TcpListener listener;
|
||||
|
||||
// Listen to the given port for incoming connections
|
||||
if (listener.Listen(port) != sf::Socket::Done)
|
||||
if (listener.listen(port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
||||
|
||||
// Wait for a connection
|
||||
sf::TcpSocket socket;
|
||||
if (listener.Accept(socket) != sf::Socket::Done)
|
||||
if (listener.accept(socket) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Client connected: " << socket.GetRemoteAddress() << std::endl;
|
||||
std::cout << "Client connected: " << socket.getRemoteAddress() << std::endl;
|
||||
|
||||
// Send a message to the connected client
|
||||
const char out[] = "Hi, I'm the server";
|
||||
if (socket.Send(out, sizeof(out)) != sf::Socket::Done)
|
||||
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
||||
|
||||
// Receive a message back from the client
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
if (socket.Receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Answer received from the client: \"" << in << "\"" << std::endl;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ void RunTcpServer(unsigned short port)
|
|||
/// welcome message and send an answer.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void RunTcpClient(unsigned short port)
|
||||
void runTcpClient(unsigned short port)
|
||||
{
|
||||
// Ask for the server address
|
||||
sf::IpAddress server;
|
||||
|
@ -62,20 +62,20 @@ void RunTcpClient(unsigned short port)
|
|||
sf::TcpSocket socket;
|
||||
|
||||
// Connect to the server
|
||||
if (socket.Connect(server, port) != sf::Socket::Done)
|
||||
if (socket.connect(server, port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Connected to server " << server << std::endl;
|
||||
|
||||
// Receive a message from the server
|
||||
char in[128];
|
||||
std::size_t received;
|
||||
if (socket.Receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message received from the server: \"" << in << "\"" << std::endl;
|
||||
|
||||
// Send an answer to the server
|
||||
const char out[] = "Hi, I'm a client";
|
||||
if (socket.Send(out, sizeof(out)) != sf::Socket::Done)
|
||||
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
/// Launch a server, wait for a message, send an answer.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void RunUdpServer(unsigned short port)
|
||||
void runUdpServer(unsigned short port)
|
||||
{
|
||||
// Create a socket to receive a message from anyone
|
||||
sf::UdpSocket socket;
|
||||
|
||||
// Listen to messages on the specified port
|
||||
if (socket.Bind(port) != sf::Socket::Done)
|
||||
if (socket.bind(port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Server is listening to port " << port << ", waiting for a message... " << std::endl;
|
||||
|
||||
|
@ -25,13 +25,13 @@ void RunUdpServer(unsigned short port)
|
|||
std::size_t received;
|
||||
sf::IpAddress sender;
|
||||
unsigned short senderPort;
|
||||
if (socket.Receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message received from client " << sender << ": \"" << in << "\"" << std::endl;
|
||||
|
||||
// Send an answer to the client
|
||||
const char out[] = "Hi, I'm the server";
|
||||
if (socket.Send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
|
||||
if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ void RunUdpServer(unsigned short port)
|
|||
/// Send a message to the server, wait for the answer
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void RunUdpClient(unsigned short port)
|
||||
void runUdpClient(unsigned short port)
|
||||
{
|
||||
// Ask for the server address
|
||||
sf::IpAddress server;
|
||||
|
@ -57,7 +57,7 @@ void RunUdpClient(unsigned short port)
|
|||
|
||||
// Send a message to the server
|
||||
const char out[] = "Hi, I'm a client";
|
||||
if (socket.Send(out, sizeof(out), server, port) != sf::Socket::Done)
|
||||
if (socket.send(out, sizeof(out), server, port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
||||
|
||||
|
@ -66,7 +66,7 @@ void RunUdpClient(unsigned short port)
|
|||
std::size_t received;
|
||||
sf::IpAddress sender;
|
||||
unsigned short senderPort;
|
||||
if (socket.Receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message received from " << sender << ": \"" << in << "\"" << std::endl;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue