Therefore my recv is working just fine. But I then try to send the USER and NICK command to the IRC server (which should produce a crapload of messages from the server), but it doesn't seem to be going through. I know its not sending because my friend is hosting the IRC server, and can detect when someone sends the USER and NICK commands, and he is getting nothing when I supposively send. I am getting no response from the server when I try to send it data... not even an error message when I send some spam. Any help would be greatly appreciated.
NOTE: I'm coding in Windows, using winsock2 library.
Code:
Socket connection, setup, etc.
Code:
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup(wVersionRequested, &wsaData );
if(err != 0) {
printf("WSA startup fail.\n");
}
m_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(m_socket == INVALID_SOCKET){
printf( "Error at socket(): %ld\n", WSAGetLastError() );
}
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( hostToIP("irc.XXX.com") );
clientService.sin_port = htons( 6667 );
if ( connect( m_socket, (SOCKADDR*) &clientService,
sizeof(clientService) ) == SOCKET_ERROR) {
printf( "Failed to connect.\n" );
WSACleanup();
} else {
printf("Connection Success!\n\n");
}
send() loop:
Code:
do {
if((s_ready = select(0, NULL, &fd, NULL, NULL)) != SOCKET_ERROR) {
gets(input);
if(strstr("/q", input)) break;
bSent = send(m_socket, input, sizeof(char)*strlen(input), 0);
printf("Sent(%d): %s\n", bSent, input);
flusher(input);
}
} while (1);
recv() loop:
Code:
while(go == 1) {
if((err = ioctlsocket(m_socket, FIONREAD, &l)) == SOCKET_ERROR) {
printf("Error: ioctlsocket(). error: %d\n", WSAGetLastError());
break;
} else if(l > 0) {
printf("Trying to recieve...\n");
bytesIn = recv(m_socket, rec, BUFFMAX, 0);
if(bytesIn > 0) {
printf("%s", rec);
rec[0] = '\0';
}
}
ready = 1;
}
The two latter snippets of code are running simotaneously via multithreading. This program shoould essentially be a telnet program untill I get some command parsing going on
.
Note 2: flusher() and hostToIP() are functions that I have created.