Jump to content
  • Advertisement
Sign in to follow this  
Antonym

Portable Begginer

This topic is 3086 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a small and simple networking program I developed in windows and visual studio 2008 with SFML and was wondering what steps I would have to go through to be able to run it on a mac too.

Heard that while windows uses exes macs use dmgs.

Any info is much appreciated.

The two cpps the project consists of in case someone wants to take a look. Taken mostly from one of the SFML samples. The project uses one SFML dll.

#include <iostream>

void DoClientTCP(unsigned short Port);
void DoServerTCP(unsigned short Port);

int main()
{
// Choose a random port for opening sockets (ports < 1024 are reserved)
const unsigned short Port = 2435;

// Client or server ?
char Who;
std::cout << "Do you want to be a server ('s') or a client ('c') ? ";
std::cin >> Who;

if (Who == 's')
{
DoServerTCP(Port);
}
else
{
DoClientTCP(Port);
}

// Wait until the user presses 'enter' key
std::cout << "Press enter to exit..." << std::endl;
std::cin.ignore(10000, '\n');
std::cin.ignore(10000, '\n');

return EXIT_SUCCESS;
}






#include <SFML/Network.hpp>
#include <iostream>

void DoClientTCP(unsigned short Port)
{
// Create a TCP socket for communicating with server
sf::SocketTCP Client;
sf::IPAddress Address = sf::IPAddress::GetPublicAddress();

// Connect to the specified server
if (Client.Connect(Port, Address) != sf::Socket::Done)
return;
std::cout << "Connected to server " << Address << std::endl;

char message[128];
bool send = true;
while(true){
if(send){
std::cin >> message;

// Send the message
if (Client.Send(message, sizeof(message)) != sf::Socket::Done)
return;
std::cout << "Message sent to server : \"" << message << "\"" << std::endl;
}
else{
// Receive a message from the client
std::size_t Received;
if (Client.Receive(message, sizeof(message), Received) != sf::Socket::Done)
return;

// Show it
std::cout << "Message received from server : \"" << message << "\"" << std::endl;

break;
}

send = !send;
}

// Close the socket when we're done
Client.Close();
}

void DoServerTCP(unsigned short Port)
{
// Create a TCP socket for communicating with clients
sf::SocketTCP Server;

// Listen to a port for incoming connections
if (!Server.Listen(Port))
return;
std::cout << "Server is listening to port " << Port << ", waiting for connections... " << std::endl;

// Wait for a connection
sf::IPAddress ClientAddress;
sf::SocketTCP Client;
Server.Accept(Client, &ClientAddress);
std::cout << "Client connected : " << ClientAddress << std::endl;

bool recieve = true;
char message[128];
while(true){
if(recieve){
// Receive a message back from the client
std::size_t Received;
if (Client.Receive(message, sizeof(message), Received) != sf::Socket::Done)
return;

// Show the message
std::cout << "Message received from the client : \"" << message << "\"" << std::endl;

}
else{
// Send a message to the client
if (Client.Send(message, sizeof(message)) != sf::Socket::Done)
return;
std::cout << "Message sent to the client : \"" << message << "\"" << std::endl;
}

recieve = !recieve;
}

// Close the sockets when we're done
Client.Close();
Server.Close();
}







Share this post


Link to post
Share on other sites
Advertisement
If you used only SFML libary's or at least no windows specific libary's, you can port it to mac.

You need to take your source to a mac machine
then download the sfml mac package and compile your application.

That should do it.


assainator

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!