Hi there, i am looking for an assistance from some one who is familiar to socket programming, or dealt with it before.
I wrote a client-server program and all the methods worked means the socket(), connect(),send(), recv() and close() in the client side, and in the server side also i used the socket(), bind(), listen(), accept(), recv(), send(), and close(). Both terminals showed a positive outcome. What i am looking for is that to type a "Hi" string in client side and to read it in the server terminal. So am looking for your assistance.
Here with the codes of both the client and server programs that i did:
client program
#include <ws2tcpip.h>
#include <iostream>
using namespace std;
int main( void ){
char ip;
unsigned short port;
port = 333;
//int count;
//Create Socket File Descriptor (pointer to where the socket is in memory)
cout << "Creating socket file descriptor... ";
SOCKET clientSocketFD = socket(AF_INET, SOCK_STREAM,IPPROTO_TCP);
if (clientSocketFD!=INVALID_SOCKET){cout<<"Complete.\n";}else{cout<<WSAGetLastError()<<"-ERROR!\n";}
//---------------------------------------------------
//connect() a connection to the socket
cout << "Connecting to the server... ";
SOCKET conerr = connect(clientSocketFD, (sockaddr*)&serverserviceFD, sizeof(serverserviceFD));
if (conerr == -1){
cout << WSAGetLastError() << " - ERROR!\n";
}
else{
cout << "Complete.\n\n";
cout<<"-----------------------------\n";
}
//send() a piece of data sendbuf
cout << "Sending information to server... ";
int sendData = send(clientSocketFD,sendbuf,strlen(sendbuf),0);
//------------------------------------------------------------------------------
//Create Socket File Descriptor (pointer to where the socket is in memory)
cout << "Creating socket file descriptor... ";
SOCKET serverserviceFD = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
if (serverserviceFD!=INVALID_SOCKET){cout<<"Complete.\n";}else{cout<<WSAGetLastError()<<"-ERROR!\n";}
//-------------------------------------------------------------------
//bind() the Socket to the specified port
cout << "Bind the socket to the specified port";
SOCKET binderr = bind(serverserviceFD, (struct sockaddr*)&serverservice, sizeof(serverservice));
if (binderr==-1){cout<<WSAGetLastError()<<"-ERROR!\n";}else{cout<< "Complete.\n";}