Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualXooch

Posted 19 April 2013 - 06:51 AM

Hey there, 

 

I'm trying to create a simple UDP socket, and send packets between the server and clients, although I'm getting a very strange error, I can't seem to figure out how to fix it, would really appreciate any help.

 

 

This is code for my client, creating the socket

void Application::Init_Winsock()
{
	WSAStartup(MAKEWORD(2,2), &Winsock);

	if(LOBYTE(Winsock.wVersion) !=2 || HIBYTE(Winsock.wVersion) !=2)	//Check version
	{
		WSACleanup();	//Cleanup and return false if version is wrong
		return;
	}

	//Create Socket
	Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

	//Input Receiver Information
	ZeroMemory(&RemoteAddress, sizeof(RemoteAddress));				//Clear Struct
	RemoteAddress.sin_family = AF_INET;								//Set the Address Family
	RemoteAddress.sin_addr.s_addr = inet_addr(SERVER_ADDRESS);		//Set IP Address
	RemoteAddress.sin_port = SERVER_PORT;							//Set Port
}

void Application::Send_Packet(PLAYER* data)
{
	sendto(Socket, (char*)data, sizeof(PLAYER), 0, (sockaddr*)&RemoteAddress, sizeof(sockaddr));
}

 

And these are the errors:

 

clienterrorb.png

 

 

And then I'm getting a very similar problem with my Server application as well, here is the code for the server, I've also declared RecvThread as a static:

		static DWORD WINAPI RecvThread(LPVOID);

 

void Application::Init_Winsock()
{
	WSAStartup(MAKEWORD(2,2), &Winsock);

	if(LOBYTE(Winsock.wVersion) !=2 || HIBYTE(Winsock.wVersion) !=2)	//Check Version
	{
		WSACleanup();	//Cleanup and end if not version 2
		return;
	}

	//Create Socket
	Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

	//Input Reciever Information
	ZeroMemory(&RemoteAddress, sizeof(RemoteAddress));		//Clear Struct
	RemoteAddress.sin_family = AF_INET;						//Set the Family Address
	RemoteAddress.sin_port = SERVER_PORT;					//Set Port
	bind(Socket, (sockaddr*)&RemoteAddress, sizeof(RemoteAddress));

	//Start the recieve thread
	////CreateThread(NULL, 0, RecvThread, NULL, 0, NULL);

	CreateThread(NULL, 0, RecvThread, (void*)this, 0, NULL);
}

DWORD WINAPI Application::RecvThread(LPVOID knock)
{
	/*
	while(true)
	{
		PLAYER Recv;
		recvfrom(Socket, (char*)&Recv, sizeof(PLAYER), 0, (sockaddr*)&RemoteAddress, &SizeInt);

		Player = Recv;
	}
	*/

	Application *instance = static_cast<Application *>(knock);
	while(true)
	{
		PLAYER Recv;
		recvfrom(instance->Socket, (char*)&Recv, sizeof(PLAYER), 0, (sockaddr*)&instance->RemoteAddress, &instance->SizeInt);

		instance->Player = Recv;
	}
}

 

and again, very similar error:

 

clienterrorb.png

 

I'm stumped :S


#1Xooch

Posted 19 April 2013 - 06:50 AM

Hey there, 

 

I'm trying to create a simple UDP socket, and send packets between the server and clients, although I'm getting a very strange error, I can't seem to figure out how to fix it, would really appreciate any help.

 

 

This is code for my client, creating the socket

void Application::Init_Winsock()
{
	WSAStartup(MAKEWORD(2,2), &Winsock);

	if(LOBYTE(Winsock.wVersion) !=2 || HIBYTE(Winsock.wVersion) !=2)	//Check version
	{
		WSACleanup();	//Cleanup and return false if version is wrong
		return;
	}

	//Create Socket
	Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

	//Input Receiver Information
	ZeroMemory(&RemoteAddress, sizeof(RemoteAddress));				//Clear Struct
	RemoteAddress.sin_family = AF_INET;								//Set the Address Family
	RemoteAddress.sin_addr.s_addr = inet_addr(SERVER_ADDRESS);		//Set IP Address
	RemoteAddress.sin_port = SERVER_PORT;							//Set Port
}

void Application::Send_Packet(PLAYER* data)
{
	sendto(Socket, (char*)data, sizeof(PLAYER), 0, (sockaddr*)&RemoteAddress, sizeof(sockaddr));
}

 

And these are the errors:

 

clienterrorb.png

 

 

And then I'm getting a very similar problem with my Server application as well, here is the code for the server, I've always declared RecvThread as a static:

		static DWORD WINAPI RecvThread(LPVOID);

 

void Application::Init_Winsock()
{
	WSAStartup(MAKEWORD(2,2), &Winsock);

	if(LOBYTE(Winsock.wVersion) !=2 || HIBYTE(Winsock.wVersion) !=2)	//Check Version
	{
		WSACleanup();	//Cleanup and end if not version 2
		return;
	}

	//Create Socket
	Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

	//Input Reciever Information
	ZeroMemory(&RemoteAddress, sizeof(RemoteAddress));		//Clear Struct
	RemoteAddress.sin_family = AF_INET;						//Set the Family Address
	RemoteAddress.sin_port = SERVER_PORT;					//Set Port
	bind(Socket, (sockaddr*)&RemoteAddress, sizeof(RemoteAddress));

	//Start the recieve thread
	////CreateThread(NULL, 0, RecvThread, NULL, 0, NULL);

	CreateThread(NULL, 0, RecvThread, (void*)this, 0, NULL);
}

DWORD WINAPI Application::RecvThread(LPVOID knock)
{
	/*
	while(true)
	{
		PLAYER Recv;
		recvfrom(Socket, (char*)&Recv, sizeof(PLAYER), 0, (sockaddr*)&RemoteAddress, &SizeInt);

		Player = Recv;
	}
	*/

	Application *instance = static_cast<Application *>(knock);
	while(true)
	{
		PLAYER Recv;
		recvfrom(instance->Socket, (char*)&Recv, sizeof(PLAYER), 0, (sockaddr*)&instance->RemoteAddress, &instance->SizeInt);

		instance->Player = Recv;
	}
}

 

and again, very similar error:

 

clienterrorb.png

 

I'm stumped :S


PARTNERS