Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Send and receive in TCP/IP

Send and receive in TCP/IP

Scheduled Pinned Locked Moved Unsolved C++ Gurus
3 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    isan
    wrote on last edited by A Former User
    #1

    in my client side in receive function if (buffer[i] == work[i] )write 1 in pin until (c < 13)
    and when program in while,if socket receive stop to write 0 in pin,it doesn't work until while ends ,I want to socket any time receive stop it's write 0 in pin ,how can handle this?
    Client:

    bool client::conn(int num_pin_1, int num_pin_2) {
    	struct sockaddr_in serv_addr;
    	struct hostent *server;
    
    	sock = socket(AF_INET, SOCK_STREAM, 0);
    	if (sock < 0)
    		printf("ERROR opening socket");
    	else {
    		fflush(stdout);
    	}
    
    	server = gethostbyname("192.168.1.129");
    	if (server == 0) {
    		fprintf(stderr, "ERROR, no such host\n");
    		exit(0);
    	} else {
    		printf("connected");
    		fflush(stdout);
    	}
    	bzero((char *) &serv_addr, sizeof(serv_addr));
    	serv_addr.sin_family = AF_INET;
    	bcopy((char *) server->h_addr,
    	(char *)&serv_addr.sin_addr.s_addr,
    	server->h_length);
    	serv_addr.sin_port = htons(MYPORT);
    	while (connect(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
    		perror("ERROR connecting");
    	}
    
    }
    
    bool client::rec_data(int num_pin_1, int num_pin_2) {
    
    rc=recv(sock, buffer, sizeof(buffer), 0);
    	if ( rc < 0) {
    		perror("receive failed");
    		return false;
    	}
    for (int i = 0; i < 2; i++) {
    if (buffer[i] == work[i] ){	
    	while (c < 13) {	
     digitalWrite(pin2, HIGH);
     digitalWrite(pin1, LOW);
    		}
    		   }
    if (buffer[i] == Stop[i]) {
     digitalWrite(pin2,  LOW);
     digitalWrite(pin1, LOW);
    }
      }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why not use QTcpSocket ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why not use QTcpSocket ?

        I Offline
        I Offline
        isan
        wrote on last edited by isan
        #3

        @SGaist Hi, I'm use orange pi board and QT not compile on it

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved