I dont know what the problem is with this

This is my client code. when I send msg. it sends fine but and then gives me msg "segmentation fault core dumped" right after I send the msg. the result of Client connection is 0 .when it quits it says that I could not find what the problem is any idea?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
sockdesc = socket(AF_INET, SOCK_STREAM, 0);//Creating a socket
   if ( sockdesc < 0 )
   {
      cout << "Error creating socket" << endl;
      exit(0);
   }//if   
   sockdesc = socket(AF_INET, SOCK_STREAM, 0);
   if ( sockdesc < 0 )
   {
      cout << "Error creating socket" << endl;
      exit(0);
   }	
   // Set up the address record
   if ( getaddrinfo(hostname, portnum, NULL, &myinfo) != 0 )
   {
      cout << "Error getting address" << endl;
      exit(0);
   }
   // Connect to the host
     cout << "Before connect" << endl;
   connection = connect(sockdesc, myinfo->ai_addr, myinfo->ai_addrlen);
   if ( connection < 0 )
   {
      cout << "Error in connect" << endl;
      exit(0);
   }
   cout << "Client connection = " << connection << endl;
//write some msg.
//read something
close(sockdesc);	
Hey friend! Do you know how to use a debugger? This may be the perfect time to try it out! You should step through your code, and detect the exact line that is giving you an error, then focus on the variables and other things involved with that line =]

If you are using an IDE like code::blocks, it's as easy as pushing the debug option.

If you are using gcc or other command line compilers, you can use gdb! (google can help)
Topic archived. No new replies allowed.