UDP and C++.



Hi,
I have an xPC system (Host PC and Target PC) setup.
I am writing a C++ program to run on Host PC of xPC to acquire data
from Target machine.

The target machine has a UDP block at output. It sends 32
'doubles'(Matlab data type) every 4 ms. So, I should be collecting
packets of size = 256 bytes at the host machine.

However, when I run my C++ code, I get ERROR# 10040 explained on the
following MSDN URL:

<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/recv_2.asp>

Is the data transferred as 'Double' or is it ASCII?

Here is my C++ code:

#include <stdio.h>
#include <winsock2.h>

int main()
{
printf("Initialize Winsock \n");
//----------------------
// Initialize Winsock
WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != NO_ERROR)
printf("Error at WSAStartup()\n");

printf("Create a SOCKET for connecting to server \n");
//----------------------
// Create a SOCKET for connecting to server
SOCKET ConnectSocket;
ConnectSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (ConnectSocket == INVALID_SOCKET)
{
printf("Error at socket(): %ld\n", WSAGetLastError());
WSACleanup();
return 0;
}

printf("The sockaddr_in structure specifies the address family
\n");
//----------------------
// The sockaddr_in structure specifies the address family,
// IP address, and port of the server to be connected to.
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "192.168.1.102" );
clientService.sin_port = htons(25000);
//clientService.sin_addr.s_addr = htonl(INADDR_ANY);
//bind socket to specific ip, port, etc.
bind(ConnectSocket, (SOCKADDR *) &clientService,
sizeof(clientService));

printf("Connect to server.\n");
//----------------------
// Connect to server.
if ( connect( ConnectSocket, (SOCKADDR*) &clientService,
sizeof(clientService) ) == SOCKET_ERROR)
{
printf( "Failed to connect.\n" );
WSACleanup();
return 0;
}

printf("Declare and initialize variables \n");

//------------------------------------------------------------------
// Declare and initialize variables.
int bytesRecv = 0; //SOCKET_ERROR;
char recvbuf[256] = "";


//------------------------------------------------------------------
// receive data.

printf("receiving bytes... \n");
int count = 0;
while( bytesRecv != SOCKET_ERROR )
{
printf("Loop#: %i \n",count);
bytesRecv = recv( ConnectSocket, recvbuf, 32, 0 );

printf("Error in recieving data: %ld\n", WSAGetLastError());
printf( "**Bytes Recieved: %ld\n", bytesRecv );
printf(recvbuf);
if (bytesRecv == 0 || WSAGetLastError() == WSAECONNRESET)
{
printf( "Connection Closed.\n");
break;
}
printf("\n Bytes Recv: %ld\n", bytesRecv );
}
WSACleanup();
return 0;
}

Thanks in advance.
.



Relevant Pages

  • Re: Locally mount vms volumes in Linux
    ... onto the host where SIMH is running and attach it in SIMH? ... If so have a look at Kermit; there are versions for OpenVMS, Linux, DOS ... Then, on the ubuntu host i could start ckermit, connecting via ... target machines, ...
    (comp.os.vms)
  • Re: How to use the gethostbyaddr function?
    ... "daniel" wrote in message ... > // host is the IP address which I couldn't connect. ... >> And I used the IP address to connect the server host. ... >> And I didn't used the ActiveSync, I ran the target in standalone type. ...
    (microsoft.public.windowsce.app.development)
  • Re: How to use the gethostbyaddr function?
    ... The ping test between the host and target was successful. ... And I used the IP address to connect the server host. ... And I didn't used the ActiveSync, I ran the target in standalone type. ... the original source code is perfectly working in desktop pc. ...
    (microsoft.public.windowsce.app.development)
  • Re: questions: "Are you sure you want to continue connecting (yes/no)?"
    ... >> for the public key of the remote host; you get it and put an entry in the ... >server's host name followed by a comma followed by the server's IP and a space. ... >Thus it is impossible to generate such a file without connecting to the server. ...
    (comp.security.ssh)
  • Re: IP Restrictions
    ... and that's all the information the FTP server has when you connect. ... connecting to one IP address get one server, ... any host can connect when they use the alias address. ...
    (microsoft.public.inetserver.iis.ftp)