Hi,
I have been given an application that when running outputs its results through a simple char buffer into a local telnet session. I need to use these results in an application I am developing, but I don't understand how I retrieve them.
I have built a tcp client which creates a socket, binds it to the local port used by the telnet application, and then connects to the telnet session. It seems to do this fine, so far so good. My client then loops constantly using the recv() method:
My problem is that it never recieves anything :(. I built a server app to test the send() method and my client recieves a char buffer just fine, but I think the problem is the app I am connecting to only sends a buffer to the telnet, and not to my client. Is there anyway to make my client recieve the telnet messages, without reprogramming the original application?Code:int main(){
WSADATA wsaData;
struct sockaddr_in clientService;
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
system("cls");
//create SOCKET for connecting to server
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(ConnectSocket == INVALID_SOCKET){
printf("ERROR Invalid Socket: %ld\n", WSAGetLastError());
WSACleanup();
return 1;
}
printf("CLIENT: Socket created...\n");
//bind port: address family, IP address, and port
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr("127.0.0.1");
clientService.sin_port = htons(51966);
printf("CLIENT: Port bound...\n");
//connect to server
iResult = connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) );
if(iResult == SOCKET_ERROR){
closesocket (ConnectSocket);
printf("ERROR Cannot Connect: %ld\n", WSAGetLastError());
WSACleanup();
return 1;
}
printf("CLIENT: Connected to localhost...\n");
//receive messages
while(TRUE){
iResult = recv(ConnectSocket,recvbuf,recvbuflen,0);
if(iResult > 0){
//printf("Bytes received: %d\n", iResult);
printf("Recieved: %s\n", &recvbuf);
}
else if(iResult == 0){
printf("Connection closed.\n");
}
else{
printf("ERROR Message Lost: %d\n", WSAGetLastError());
}
}
Cheers for taking the time to read all this!