here is the code for the server
//---------------------------------------------------------------------------
#include <vcl.h>
#include <winsock2.h>
#include <iostream>
#pragma hdrstop
using namespace std;
char last;
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
WSADATA wsa;
SOCKET sock;
SOCKADDR_IN ServerInfo;
int port;
//----------------------
cout << "Console Server -> UG Cyber" << endl;
cout << "Press F1 to stop server" << endl << endl;
cout << "Port Desired: ";
cin >> port;
cout << endl;
//----------------------
WSAStartup(0x0202, &wsa);
ServerInfo.sin_family = AF_INET;
ServerInfo.sin_port = htons(port);
ServerInfo.sin_addr.s_addr = inet_addr("0.0.0.0");
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (bind(sock, (SOCKADDR*)&ServerInfo, sizeof(ServerInfo)) == INVALID_SOCKET)
{
cout << "Could not bind to port " << port << endl;
return 1;
}
listen(sock, 10);
accept(sock, NULL, NULL);
while (GetAsyncKeyState(VK_F1) != true)
{
char Buffer[1024];
recv(sock, Buffer, 1024, 0);
if (Buffer[0] != last)
{
cout << "Client-> " << Buffer << endl;
Buffer[0] = last;
}
}
return 0;
}
and here is the console client i also created...
//---------------------------------------------------------------------------
#include <vcl.h>
#include <winsock2.h>
#include <iostream>
#pragma hdrstop
using namespace std;
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
WSADATA wsa;
SOCKET sock;
SOCKADDR_IN Host;
char IPAddress[1024];
int Port;
//-----------------
cout << "Console TCP client -> UG Cyber" << endl << endl;
cout << "IP: ";
cin >> IPAddress;
cout << endl << "Port: ";
cin >> Port;
cout << endl;
//-----------------
WSAStartup(0x0202, &wsa);
Host.sin_family = AF_INET;
Host.sin_port = htons(Port);
Host.sin_addr.s_addr = inet_addr(IPAddress);
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET)
{
cout << "Socket Invalid" << endl;
return 1;
}
if (connect(sock, (SOCKADDR*)&Host, sizeof(Host)) == SOCKET_ERROR)
{
cout << "Could not connect to " << IPAddress << endl;
return 1;
}
while (true)
{
char Message[1024];
cout << "Send: ";
cin >> Message;
cout << endl;
//----------------
if (send(sock, Message, sizeof(Message), 0) == SOCKET_ERROR)
{
cout << "Fatal error: Could not send message" << endl;
cout << "Disconnecting....." << endl;
break;
}
}
return 1;
}
I am not getting any errors and it does connect....but wont send/receive anything readable.

New Topic/Question
Reply



MultiQuote





|