Monday, 15 June 2015

sockets - SEgemenattation Error in Multithreading -


Follow the output for the given code as I try to create multiple connections to client server programs with different sockets Is coded.

While loop to create thread for each flow ... the problem arises

Please help!

Sudhakar @ rcs-HP-xw4300- Workstation: ~ / Desktop $ GCC UTGen C -O Sender -Va-ElphthreadCoder @ RCS-HP-Exx 4300- Workstation: ~ / Desktop $ ./ Sender-M1-S Localhost-P5000-G 1024-T10-PT-F4

Aggregation for Port Number 5000
Aggregation for Port No. 5001
Port No aggregation for 5003
Port number Coordination for 5006
/ Sender: Segmentation fault (core dipped)

  Start zero \ t_T_flow () {gettimeofday (& TV1, zero); Do {n = write (sockhead, buffer, packet_size); Num_pkt_send ++; TotalSend = TotalSend + n; If (n & lt; 0) {error ("Writing to Error Socket"); Exit (1); } // printf ("Send% d bytes:% d \ n", num_pkt_seend, n); Gettimeofday (& amp; TV2, NULL); Memeset (buffer, 0, safffer buffer); } While (1 / * (tv2.tv_sec-tv1.tv_sec) & lt; = Sen_Loop_time * /); } Zero * Send_tcp (int portno) {int port = portno; Socketnum = port-5000; Sockfd [socketnum] = create_tcp_socket (); Setbuffer (Sokfad [Soketnam]); Berzo ((* four *) and serv-aardro, sapphire (servo_adro); Serv_addr.sin_family = AF_INET; Beacopie ((* four *) server-> HADR, (four *) and servo_ADCININIDS_AD, server-> H_Long); Serv_addr.sin_port = htons (port); If (connect (sockfd, (struct sockaddr *) and serv_addr, sizeof (serv_addr)) 0 error ("add error"); printf ("port \ n port number% d connected", port); int i I = l; packet_size; i ++ buffer = i; i =) buffer for i = i; i = l; sokfad (sokatam), ipprtoodlpc, tcp_nodel, (zero *) and i, sb (i) A '; Printf ("Port started sending traffic for port number", port); Start_TCP_flow (); Sen_Loop_time = (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - Tv1.tv_sec); closed (sokfad [soketanum]);}  

this main function The code is part of the code:

  int i; pthread_t tid [NUM_THREADS]; for intense sockford [NUM_THREADS]; int NewsFocked [NUM_THREADS]; for (i = 0; i & lt; NUM_THREADS ; I ++) {portno = portno + i; Printf ("\ n" Coaching for port number% d "); Pthread_create (& amp; tid [i], faucet, Send_tcp, portno); // pthread_join ( Tid [0], NULL);} (i = 0; i & lt; NUM_THREADS; i ++) pthread_join (tid [i], NULL); pthread_exit (zero);  

You are adding loop index 'I' to portno in main () . This means that 'socketed [socketnam] = build_tCP_ socket ();' Essentially unsuccessful in a thread because sockettonum index increases beyond the limit of socketfum [NUM_THREADS].

Do you have to add one instead of 'I'?

It is not surprising that you have not seen this with special importance in numbers during your debugging:

  Connecting for port number 5000; Port number Consolidation for 5001; // Adds i which is Coonecting 1 for port number 5003; // Adds i port number For 5006 is 2 Coonecting; // AIDS I is 3  

No comments:

Post a Comment