Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting bytes to uint32 in C
    primarykey
    data
    text
    <p>I'm continuously sending arrays of pixel values (uint32) from LabVIEW to a C-program through TCP/IP. I'm using the recv function in Ws2_32.lib to receive the bytes, but I have to convert them back to uint32 data type and doesn't really know how to do it in this case. I'll be thankful if anyone shows how to do it. </p> <p>Thanks in advance</p> <pre><code>#define DEFAULT_BUFLEN 256 #include&lt;stdio.h&gt; #include&lt;winsock2.h&gt; #pragma comment(lib,"ws2_32.lib") //Winsock Library int main(int argc , char *argv[]) { WSADATA wsa; SOCKET s , new_socket; struct sockaddr_in server , client; int c; typedef unsigned char bytes[256]; typedef unsigned int uint32_t; int iResult; char recvbuf[DEFAULT_BUFLEN]; int recvbuflen = DEFAULT_BUFLEN; printf("\nInitialising Winsock..."); if (WSAStartup(MAKEWORD(2,2),&amp;wsa) != 0) { printf("Failed. Error Code : %d",WSAGetLastError()); return 1; } printf("Initialised.\n"); //Create a socket if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET) { printf("Could not create socket : %d" , WSAGetLastError()); } printf("Socket created.\n"); //Prepare the sockaddr_in structure server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons( 13000 ); //Bind if( bind(s ,(struct sockaddr *)&amp;server , sizeof(server)) == SOCKET_ERROR) { printf("Bind failed with error code : %d" , WSAGetLastError()); } puts("Bind done"); //Listen to incoming connections listen(s , 3); //Accept and incoming connection puts("Waiting for incoming connections..."); c = sizeof(struct sockaddr_in); new_socket = accept(s , (struct sockaddr *)&amp;client, &amp;c); if (new_socket == INVALID_SOCKET) { printf("accept failed with error code : %d" , WSAGetLastError()); } do { iResult = recv(new_socket, recvbuf, recvbuflen, 0); if ( iResult &gt; 0 ) printf("%d\n", iResult); else if ( iResult == 0 ) printf("Connection closed\n"); else printf("recv failed: %d\n", WSAGetLastError()); } while( iResult &gt; 0 ); closesocket(s); WSACleanup(); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload