Har igen lidt problemer med socket.
Har denn kode:
#include <iostream>
#include "winsock2.h"
using namespace std;
void main() {
struct sockaddr_in addr;
WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != NO_ERROR)
cout << "Kunne ikke starte WSA" << endl;
SOCKET m_socket;
m_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (m_socket == INVALID_SOCKET) {
cout << "Fejl ved socket(): " << WSAGetLastError() << endl;
WSACleanup();
return;
}
addr.sin_family = AF_INET;
addr.sin_port = htons(7524);
addr.sin_addr = "192.168.0.53";
int recv, send;
char sendBuf[1024] = "VAL aloha aloha";
char recvBuf[1024];
send = sendto(m_socket, sendBuf, sizeof(sendBuf), 0, (struct sockaddr*)&addr, sizeof(sockaddr_in));
if (send < 0) {
cout << "Kunne ikke forbinde til serveren (send)" << WSAGetLastError() << endl;
system("PAUSE");
return;
}
addr.sin_family = AF_INET;
addr.sin_port = htons(7524);
addr.sin_addr.s_addr = INADDR_ANY;
recv = recvfrom(m_socket, recvBuf, sizeof(recvBuf), 0, (struct sockaddr*)&addr, sizeof(sockaddr_in));
if (recv < 0) {
cout << "Kunne ikke forbinde til serveren" << endl;
system("PAUSE");
return;
} else {
if (recvBuf != 0) {
cout << "Du blev ikke logget ind" << endl;
} else {
cout << "Du er logget ind" << endl;
}
}
system("PAUSE");
closesocket(m_socket);
shutdown(m_socket, 0);
}
og får fejl:
c:\\Documents and Settings\\Kasper Nielsen\\Dokumenter\\Visual Studio\\Projects\\Identifa login\\Identifa login\\main.cpp(25) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const char [13]' (or there is no acceptable conversion)
c:\\Documents and Settings\\Kasper Nielsen\\Dokumenter\\Visual Studio\\Projects\\Identifa login\\Identifa login\\main.cpp(42) : error C2664: 'recvfrom' : cannot convert parameter 6 from 'size_t' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast