| | |
help pls..."connect: Connection refused"
![]() |
Hello there, I'm currently practicing network programming under Unix system. I have here a sample code from the tutorial. I compiled it, it has no errors. But when I execute it, it prompts me this "connect: Connection refused". What do you think is the problem. Here's my code:
Help please.
c++ Syntax (Toggle Plain Text)
#include <netinet/in.h> #include <sys/socket.h> #include <netdb.h> #include <sys/types.h> #include <iostream> #define PORT 13 #define BUFLEN 1024 using namespace std; struct sockaddr_in s_add; int suck_it, bind_me, r_con; char* p_buff; char buf[BUFLEN+1]; struct hostent* h_name; int main(int argc, char *argv[]){ if(argc < 2){ cout << "Missing hostname" << endl; exit(1); } h_name = gethostbyname(argv[1]); if(!h_name){ cout << "couldn't resolve host name" << endl; } memset(&s_add, 0, sizeof(s_add)); s_add.sin_family = AF_INET; s_add.sin_port = htons(PORT); memcpy(&s_add.sin_addr.s_addr, h_name->h_addr_list[0], h_name->h_length); suck_it = socket(AF_INET, SOCK_STREAM, 0); if(suck_it<=-1){ perror("im your worst nightmare"); } r_con = connect(suck_it, (struct sockaddr*) &s_add, sizeof(s_add)); if(r_con){ perror("connect"); } p_buff = buf; r_con = read(suck_it, p_buff, BUFLEN-(p_buff-buf)); while(r_con){ p_buff += r_con; } close(suck_it); *p_buff = ' '; cout << "Time: " << buf; return 0; }
Help please.
Retreat!!!
![]() |
Similar Threads
- DNS Problem - rndc: connect failed: connection refused (*nix Software)
- "Connection was refused error". Problems signing into Hotmail & Yahoo (secure) (Web Browsers)
Other Threads in the *nix Software Forum
- Previous Thread: winxp, virtyalbox, mandriva and ssh ?
- Next Thread: Email ticketing software
Views: 2080 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for *nix Software
2005 apache bashscripting busybox cert codeplex debian dotnetnuke emacs forwarding free fsf gaming gnu government gpl lawsuits license linux ls mail make makefile mandriva microsoft mkisofsiso obama open opensource port postfix ps3 samba security server sflc sharing software source stallman subdirectory ubuntu unix vmware xbox






