#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;
}
错误16 错误LNK2019:函数_Transmit中引用了未解析的外部符号_WSACleanup @ 0
错误17 错误LNK2019:函数_Transmit中引用的未解析的外部符号_XcpIp_RxCallback
错误18 错误LNK2019:函数_Transmit中引用的未解析的外部符号_recv @ 16
错误19 错误LNK2019:函数_Transmit中引用的未解析的外部符号_closesocket @ 4
错误20 错误LNK2019:函数_Transmit中引用的未解析的外部符号_XcpIp_TxCallback
错误21 错误LNK2019:函数_Transmit
中引用了未解析的外部符号_send @ 16错误22 错误LNK2019:函数_Transmit中引用的未解析的外部符号_inet_ntoa @ 4
错误23 错误LNK2019:函数_Transmit中引用的未解析的外部符号_ntohs @ 4
错误24 错误LNK2019:未解析的外部符号_accept @ 12在函数中引用_Transmit
错误25 错误LNK2019:函数_Transmit中引用的未解析的外部符号_listen @ 8
错误26 错误LNK2019:函数_Transmit中引用的未解析的外部符号_bind @ 12
错误27 错误LNK2019:函数_Transmit中引用的未解析的外部符号_htons @ 4
错误28 错误LNK2019:函数_Transmit中引用了未解析的外部符号_inet_addr @ 4
错误29 错误LNK2019:函数_Transmit中引用的未解析的外部符号_socket @ 12
错误30 错误LNK2019:函数_Transmit中引用了未解析的外部符号_WSAGetLastError @ 0
错误31 错误LNK2019:函数_Transmit中引用的未解析的外部符号_WSAStartup @ 8
错误32 致命错误LNK1120:16个未解析的外部
我在服务器端创建了一个套接字,并通过特定端口从内存中发送数据,并且同一程序也会接受端口中的数据。编译完上面的程序后,得到一些错误。有人可以帮我修理它。