Hello. This is probably a noob question, but I have a sender program and a receiver program that send or receive Packets through TCP Sockets. The code for each is as follows:
Send
#include <SFML/Network.hpp>
#include <iostream>
//////////////////////////////////////////////
// STICS - Simple Two-Way Internet Chat System
// Server Program - Version 0.3
// Uses the SFML network library
// By David Phillips (2010-2011)
//////////////////////////////////////////////
using namespace std;
int main()
{
cout << "STICS - Simple Two-Way Internet Chat System" << endl << "By David Phillips (2010-2011)" << endl << endl;
cout << "Enter the server port:" << endl;
int ServerPort;
cin >> ServerPort;
cout << "Awaiting connection..." << endl;
sf::SocketTCP Listener;
if (!Listener.Listen(ServerPort))
{
cout << "Could not create socket" << endl;
return 0;
}
sf::IPAddress ServerAddress;
sf::SocketTCP ServerRec;
if (Listener.Accept(ServerRec, &ServerAddress) != sf::Socket::Done)
{
cout << "Error with server connection." << endl;
return 0;
}
cout << "Ready" << endl;
sf::Packet Received;
string RecTemp;
//Receiving loop
do
{
ServerRec.Receive(Received);
Received >> RecTemp;
cout << RecTemp << endl;
} while (true);
}
Receiver
#include <SFML/Network.hpp>
#include <iostream>
//////////////////////////////////////////////
// STICS - Simple Two-Way Internet Chat System
// Client Program - Version 0.4
// Uses the SFML network library
// By David Phillips (2010-2011)
//////////////////////////////////////////////
using namespace std;
int main()
{
cout << "STICS - Simple Two-Way Internet Chat System" << endl << "By David Phillips (2010-2011)" << endl << endl;
char ServerIP[64];
int ServerPort;
cout << "Enter server IP:" << endl;
cin >> ServerIP;
cout << endl << "Enter server port:" << endl;
cin >> ServerPort;
sf::SocketTCP ServerSend;
connect:
cout << "Connecting to " << ServerIP << " on port " << ServerPort << "..." << endl;
if (ServerSend.Connect(ServerPort, ServerIP) != sf::Socket::Done)
{
cout << "Connection timed out" << endl;
goto connect;
}
sf::Packet ToSend;
string SendTemp;
cout << "Connection to " << ServerIP << " made. STICS is now ready to chat!" << endl;
do
{
getline(cin,SendTemp);
ToSend << SendTemp;
ServerSend.Send(ToSend);
} while (true);
}
(Sorry for the inefficient coding, I'm just starting C++ and using the SFML Libraries)
When I send something to the receiver, there is just a blank line put on the console window for the Receiver - the packet's empty!!
Could I please get some help on this??
Thanks a lot!!!