#include <stdio.h>
#include <windows.h>
typedef unsigned _int16 uint16;
typedef unsigned _int8 uint8;
typedef unsigned _int32 uint32;
uint32 measurements[32];
void Transmit(uint16 port, int* pBytes, uint16 numBytes);
int main()
{
uint16 port;
uint16 numBytes;
int* pBytes;
port =18000;
pBytes = &measurements;
numBytes = strlen(pBytes);
Transmit(port, &pBytes, numBytes);
return 0;
}
void Transmit(uint16 port, int* pBytes, uint16 numBytes) // this function must transmit the specified byte on IP connection identified by port
{
WSADATA wsa;
SOCKET s, new_socket;
int bytes_recieved;
int sin_size;
struct sockaddr_in server, client; // creating a socket address structure: structure contains ip address and port number
uint16 numTxBytes;
uint8* pChunkData;
uint16 chunkLen;
numTxBytes = 1;
printf("Initializing Winsock\n");
if(WSAStartup(MAKEWORD(2,2), &wsa)!=0)
{
printf("Failed Error Code", WSAGetLastError());
return 1;
}
printf("Initialised\n");
//CREATING a SOCKET
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("Could not Create Socket\n");
return 0;
}
printf("Socket Created\n");
server.sin_addr.s_addr = inet_addr("127.0.0.1");
server.sin_family = AF_INET;
server.sin_port = htons(port);
//Binding between the socket and ip address
if(bind (s, (struct sockaddr *) &server, sizeof(server)) == SOCKET_ERROR)
{
printf("Bind failed with error code: %d", WSAGetLastError());
}
puts("Bind Done");
//Listen to incoming connections from the client
listen(s, 3);
//Accepting the incoming connection
while(1)
{
sin_size = sizeof(struct sockaddr_in);
new_socket = accept(s, (struct sockaddr *)&client, &sin_size);
printf("\n I got a connection from (%s , %d)",
inet_ntoa(client.sin_addr),ntohs(client.sin_port));
while (1)
{
if (strcmp(pBytes , "q") == 0 || strcmp(pBytes , "Q") == 0)
{
send(new_socket, pBytes ,numBytes, 0);
closesocket(new_socket);
break;
}
else
send(new_socket, pBytes, numBytes , 0);
pChunkData = &measurements;
chunkLen = sizeof(pChunkData);
bytes_recieved = recv(new_socket, pChunkData, chunkLen ,0 );
pChunkData[bytes_recieved] = '\0';
if (strcmp(pChunkData , "q") == 0 || strcmp(pChunkData , "Q") == 0)
{
close(new_socket);
break;
}
else
printf("\n RECIEVED DATA = %s " , pChunkData);
fflush(stdout);
}
}
closesocket(s);
WSACleanup();
return 0;
}
Error 16 error LNK2019: unresolved external symbol _WSACleanup@0 referenced in function _Transmit
Error 17 error LNK2019: unresolved external symbol _XcpIp_RxCallback referenced in function _Transmit
Error 18 error LNK2019: unresolved external symbol _recv@16 referenced in function _Transmit
Error 19 error LNK2019: unresolved external symbol _closesocket@4 referenced in function _Transmit
Error 20 error LNK2019: unresolved external symbol _XcpIp_TxCallback referenced in function _Transmit
Error 21 error LNK2019: unresolved external symbol _send@16 referenced in function _Transmit
Error 22 error LNK2019: unresolved external symbol _inet_ntoa@4 referenced in function _Transmit
Error 23 error LNK2019: unresolved external symbol _ntohs@4 referenced in function _Transmit
Error 24 error LNK2019: unresolved external symbol _accept@12 referenced in function _Transmit
Error 25 error LNK2019: unresolved external symbol _listen@8 referenced in function _Transmit
Error 26 error LNK2019: unresolved external symbol _bind@12 referenced in function _Transmit
Error 27 error LNK2019: unresolved external symbol _htons@4 referenced in function _Transmit
Error 28 error LNK2019: unresolved external symbol _inet_addr@4 referenced in function _Transmit
Error 29 error LNK2019: unresolved external symbol _socket@12 referenced in function _Transmit
Error 30 error LNK2019: unresolved external symbol _WSAGetLastError@0 referenced in function _Transmit
Error 31 error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _Transmit
Error 32 fatal error LNK1120: 16 unresolved externals
I have created a socket on the server side and sending data from the memory via the specific port and also the same program will accept the data in the port. After compiling the above program, getting some errors. Could someone help me to fix it.