UDP Help

This topic is 4345 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I have just begun working on my networking class for my game, and here is what I have so far. UDP is new to me, and Sockets are not new, but I have not used them too much. Anyway, here is what I have so far in my networking header file, I am wondering if anyone could point what what I am doing wrong, and what I need to do.
class igeNetworking
{
public:
igeNetworking();

void SendPacket();
void GetPacket();

private:

SOCKET Socket;

char *sPlayerName;

};

igeNetworking::igeNetworking()
{
}

{
Socket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);

sPlayerName = sPlayerNamex;
}

void igeNetworking::SendPacket()
{
}

void igeNetworking::GetPacket()
{
//recvfrom();
}



Share on other sites
You aren't checking error values... they will at least tell you what function is messing up.

You need to set up SOCKADDR_IN structures with the IP and port. Use inet_addr() to convert your const char* into a 4-byte ip. Check MSDN for more info on that stuff.

Share on other sites
First off, everything blaze02 said!

Second, are you sure you're putting everything in network byte order? Some systems don't require it, but it doesn't hurt to try (at least with my experience).

Share on other sites

SO_BROADCAST only works on the local subnet unless there is additinal hardwar to support it at the higher levels of network hierarchy

You might also want a DisconnectFromServer() to do cleanup.....

Share on other sites
For some reason when ever I try posting, it never works :-/

Share on other sites
I have updated connect to this:

//*****************************************************// STARTS A UDP CONNECTION TO A SERVER//*****************************************************void igeNetworking::ConnectToServer(char *sIPAddressx, char *sPlayerNamex){	WSADATA wsaData;	WSAStartup(MAKEWORD(2,2), &wsaData);	struct addrinfo *result = NULL, *ptr = NULL, hints;	int iResult;	ZeroMemory(&hints, sizeof(hints));	hints.ai_family = AF_UNSPEC;	hints.sockettype = SOCK_STREAM;	hints.prototype = IPPROTO_UDP;	iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result);	Socket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);	setsockopt(Socket,IPPROTO_UDP,SO_BROADCAST,NULL,NULL);	sIPAddress = sIPAddressx;	sPlayerName = sPlayerNamex;}

but the struct addrinfo is causing problems.

Compiling...
main.cpp
c:\documents and settings\owner\desktop\insane game engine\igenetworking.h(48) : error C2079: 'hints' uses undefined struct 'addrinfo'
c:\documents and settings\owner\desktop\insane game engine\igenetworking.h(53) : error C2228: left of '.ai_family' must have class/struct/union type
c:\documents and settings\owner\desktop\insane game engine\igenetworking.h(54) : error C2228: left of '.sockettype' must have class/struct/union type
c:\documents and settings\owner\desktop\insane game engine\igenetworking.h(55) : error C2228: left of '.prototype' must have class/struct/union type
c:\documents and settings\owner\desktop\insane game engine\igenetworking.h(57) : error C2065: 'getaddrinfo' : undeclared identifier
c:\documents and settings\owner\desktop\insane game engine\igenetworking.h(57) : error C2065: 'argv' : undeclared identifier
c:\documents and settings\owner\desktop\insane game engine\igenetworking.h(57) : error C2109: subscript requires array or pointer type
Error executing cl.exe.

InsaneCombat.exe - 7 error(s), 0 warning(s)

Share on other sites

Client Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.

Declared in Wspiapi.h on Windows 2000, Windows NT, and Windows Me/98/95.

Pay special attention to the "declared in" part.

Share on other sites
Wait... I cant run a server using that UDP code unless its being run on windows server?

Share on other sites
No, that's not what the text says. Read it again. Especially this part: Header Declared in Ws2tcpip.h..

Share on other sites
Oh ok, yea I got the header part.
Same errors.

• 9
• 23
• 10
• 19