First of all, hi all
Well, i coded a udp socket with a tutorial, which i want to connect to an HL server to get some Infos(POlayers,map,...)
my program:
---------------------------------------------------------------------------------------
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
//Prototypen
int startWinsock(void);
int main()
{
long rc;
int a= -1;
SOCKET s;
char buf[256];
SOCKADDR_IN addr;
SOCKADDR_IN remoteAddr;
int remoteAddrLen=sizeof(SOCKADDR_IN);
rc=startWinsock();
if(rc!=0)
{
printf("Fehler: startWinsock, fehler code: %d\n",rc); return 1;
sleep(1000);
}
else
{
printf("Winsock gestartet!\n");
sleep(1000);
}
//UDP Socket erstellen
s=socket(AF_INET,SOCK_DGRAM,0);
if(s==INVALID_SOCKET)
{ printf("Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\n",WSAGetLastError());
sleep(1000);
return 1;
}
else
{printf("UDP Socket erstellt!\n");
sleep(1000);
}
// addr vorbereiten
addr.sin_family=AF_INET;
addr.sin_port=htons(27016);
addr.sin_addr.s_addr=inet_addr("194.112.0.163");
rc=connect(s,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN)) ;
//rc=sendto (s,buf,strlen(buf),0,(SOCKADDR*)&addr,sizeof(SOCKA DDR_IN));
rc=send(s,buf,strlen(buf),0);
if(rc==SOCKET_ERROR)
{
printf("Fehler: send, fehler code: %d\n",WSAGetLastError());
sleep(1000);
return 1;
}
else
{
printf("%d Bytes gesendet!\n", rc);
sleep(1000);
}
//rc=recvfrom(s,buf,256,0,(SOCKADDR*)&remoteAddr,&re moteAddrLen);
rc=recv(s,buf,256,0);
if(rc==SOCKET_ERROR)
{
printf("Fehler: recvfrom, fehler code: %d\n",WSAGetLastError());
sleep(1000);
return 1;
}
else
{
printf("%d Bytes empfangen!\n", rc);
sleep(1000);
buf[rc]='\0';
printf("Empfangene Daten: %s\n",buf);
sleep(1000);
}
WSACleanup();
closesocket(s);
return 0;
}
int startWinsock(void)
{WSADATA wsa;
return WSAStartup(MAKEWORD(2,0),&wsa);
}
---------------------------------------------------------------------------------------here is a short snippet from hl server protocol txt:
Remote App sends a UDP packet to the server on the server's port (e.g., 127.0.0.1:27015):
The packet should start with 4 consecutive bytes of 255 (32-bit integer -1) and the string:
"challenge rcon\n".
The server will respond to the requesting system on the purported remote IP address and port with four 255's and:
"challenge rcon number\n" where number is an unsigned int32 number.
full txt file at :
http://www.chatbear.com/cgi-bin/boar...2&view=flatold
---------------------------------------------------------------------------------------
well, i dunno really what is ment ot how to sent it since im a beginner, i would appreciate your help alot, but if you are willing to help plz make it detailed, best would be to show whats to be done with the code
Thx in advance
Tolpan