Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

telnet 21 - data channel

Status
Not open for further replies.

sncps

Programmer
Feb 27, 2003
1
US
I'm having trouble getting my data channel setup. I recieve a "150 ASCII data connection ..." and "226 ASCII Transfer complete" on the control channel, but don't recieve any data on the data channel. What am I doing wrong?


SOCKET data_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

server.sin_family = AF_INET;
server.sin_port = htons(DATAPORT);
server.sin_addr.s_addr = INADDR_ANY; // auto-fill with my IP

//bind
if(bind(data_socket, (struct sockaddr *)&server, sizeof(server)) == -1)
printf("bind() error\n");
else
cout << &quot;bind() ok\n&quot;;

//listen
data_socket = listen(data_socket, 10);
if(data_socket == -1)
cout << &quot;listen() error\n&quot;;
else
cout << &quot;listen() ok\n&quot;;

//accept
namelen = sizeof(server);
SOCKET accepted_descriptor = accept(data_socket,
(struct sockaddr *) &server,
&namelen);

if (accepted_descriptor < 0)
{
cout<<&quot;data-socket fails to connect&quot;<<endl;
exit(accepted_descriptor);
}
else
cout << &quot;accept() ok\n&quot;;

cout<<accepted_descriptor<<endl;
//accept_done

if (send(control_socket, &quot;LIST\r\n&quot;, strlen(&quot;LIST\r\n&quot;), 0) < 0)
{
cout << &quot;Client fails to send a message to the server.....\n&quot;;
}

if (recv(control_socket, buf, MAXBUFFER, 0) < 0)
{
cout << &quot;Client fails to receive the message from the server successfully.....\n&quot;;
exit(status);
}

recieve_message(buf);
strcpy(buf, &quot;&quot;); //clear the buffer


// Receive the message on the newly connected socket
if (recv(accepted_descriptor, buf, MAXBUFFER, 0) < 0)
{
cout <<&quot;data-socket fails to receive the message from the server.....\n&quot;;
//exit(status);
}
else
{
cout << &quot;data-socket receives message from the server successfully.....\n&quot;;
recieve_message(buf);
}

if (recv(control_socket, buf, MAXBUFFER, 0) < 0)
{
cout << &quot;Client fails to receive the message from the server successfully.....\n&quot;;
exit(status);
}

recieve_message(buf);
strcpy(buf, &quot;&quot;); //clear the buffer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top