Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 05 Apr 2011
Offline Last Active Dec 08 2014 09:09 AM

Topics I've Started

Get External IP Address Without 3rd Party Websites

04 December 2014 - 12:59 PM

Ive been doing some research on how to pull this off, and come to find no solutions anywhere online. Winsock alone will only retrieve your local ip address and not your external ip address. Other solutions and recommendations were to rely on 3rd party websites such as whatismyip.com. Scripting was another way. And also found that it is possible to do in C++ but is very difficult and you would need to create your own function. Even though this has been mentioned, the solutions were not presented at all. And what would really suck is if i were to rely on assembly code. Could anyone point me in the right direction on the steps needed to pull this off without resorting to 3rd party websites? Thanks in advance

Switching from CreateThread() to Thread

23 November 2014 - 06:34 PM

I made a simple chat program using a simple console window, but have one problem. Originally both my client and server were using CreateThread(), but saw some more benefits of using the thread header so I began switching it. I did the client first and so far everything works with no problems. But then I tried the server end, and the program went haywire in the loop. With no client open at all, simply running the server kept accepting clients and disconnecting clients over and over rapidly. Its suppose to pause at accept and bare in mind, no client was open at all!

After careful debugging and putting those couple of lines of code back the way it was back to CreateThread(), I found simply having #include <thread> uncommented was making my loop go haywire. I wasnt even doing anything with the header. Whats making my program act that way from that thread header? Thanks in advance

Issue With Simple Client To Server Chat Program

17 November 2014 - 03:45 PM

Hey guys. I'm a little bit new to winsock programming in C++ and ran into an issue. The server works fine with one client up. And once I get another client up, the server can receive one or two messages from the first client before it ultimately is no longer receiving messages from that client, but is able to receive unlimited messages from the 2nd client. This holds true if I were to open a 3rd client, the serve is able to pick up a message or two from the 2nd client until it no longer receives messages from that client, while its able to receive unlimited messages from the 3rd client. I can't for the life of me figure out whats going on but its the closest I've ever gotten to a simple chat program with this code I whipped up. Bare in mind I eliminated the error handling to make it easier to understand for now until I get it working.

Server code:
#include <iostream>
#include <winsock2.h>
#include <ws2tcpip.h>#
include <string>
using namespace std;
#pragma comment (lib, "Ws2_32.lib")
#define IP_ADDRESS ""
#define DEFAULT_PORT "3504"
#define DEFAULT_BUFLEN 2024
const char option_value = 1;
//Function Prototypes
DWORD WINAPI ProcessClient(LPVOID Parameter);
int main();
WSADATA wsaData;
struct addrinfo hints;
struct addrinfo *server = NULL;
SOCKET server_socket = INVALID_SOCKET;
int num_clients = 0;
string msg = "";
char tempmsg[DEFAULT_BUFLEN] = "";

DWORD WINAPI ProcessClient(LPVOID Parameter)
    cout << "Client #" << num_clients << " Accepted" << endl;	
    while (1)	
        memset(tempmsg, 0, DEFAULT_BUFLEN);			
        if (client_socket != 0)			
            int iResult = recv(client_socket, tempmsg, DEFAULT_BUFLEN, 0);
            if (iResult > 0)				
                if (strcmp("", tempmsg))
		    msg = tempmsg;					
                cout <<  msg.c_str() << endl << endl;
    return 0;

int main()
    //Initialize Winsock	
    cout << "Intializing Winsock..." << endl;	
    WSAStartup(MAKEWORD(2, 2), &wsaData);	

    //Setup hints	
    ZeroMemory(&hints, sizeof(hints));	
    hints.ai_family = AF_INET;	
    hints.ai_socktype = SOCK_STREAM;	
    hints.ai_protocol = IPPROTO_TCP;	
    hints.ai_flags = AI_PASSIVE;	

    //Setup Server	
    cout << "Setting up server..." << endl;	
    getaddrinfo(static_cast<LPCTSTR>(IP_ADDRESS), DEFAULT_PORT, &hints, &server);
    //Create a listening socket for connecting to server	
    cout << "Creating server socket..." << endl;	
    server_socket = socket(server->ai_family, server->ai_socktype, server->ai_protocol);	

    //Setup socket options	
    setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &option_value, sizeof(int)); //Make it possible to re-bind to a port that was used within the last 2 minutes	
    setsockopt(server_socket, IPPROTO_TCP, TCP_NODELAY, &option_value, sizeof(int));     //Used for interactive programs	

    //Assign an address to the server socket.	
    cout << "Binding socket..." << endl;	
    bind(server_socket, server->ai_addr, (int)server->ai_addrlen);	

    //Listen for incoming connections.	
    cout << "Listening..." << endl;	
    listen(server_socket, SOMAXCONN);	
    while (1)	
        while (client_socket = accept(server_socket, NULL, NULL))		
            DWORD threadID;			
            CreateThread(NULL, 0, ProcessClient, (LPVOID)client_socket, 0, &threadID);		    

    //Close listening socket	

    //Close client socket	

    //Clean up Winsock	
    cout << "Program has ended successfully" << endl;	
    return 0;
The client code isnt necessary, as the problem lies in here.

In attempt two to try and get it working, I tried making the client_socket an array. Although it sort of works, it works in a very bad way. For example, if I have client 1 and client 2 log on afterwards. The server can receive a message from client 1 but cant from client two until it has received a message from client 1, and vice versa. As though it gets stuck in recv() in the middle of a for loop in the thread. I have no idea on how to fix any of this and any help will be appreciated. Thanks in advance.

VS2013 Menu Item With Submenus not Disabling/Enabling

02 May 2014 - 12:28 PM

I've been stuck on this all day yesterday, and yes, I can enable and disable menu items in my Win32 window, as well as submenu items, but not menu items that contain submenus, which are menu items with a > symbol. I tried different combinations, and nothing works to disable or enable menu items that contain submenus. Not even this:


HMENU menu = GetMenu(hWnd);
HMENU submenu = GetSubMenu(menu, 0);

Is there a way to do it on menu items that contain submenus? Thanks in advance :)

Transparent Textured Polygons Not Working

19 March 2014 - 08:11 AM

Hello. I'm developing a simple app for Android using Eclipse, and I'm having a difficult time doing simple see thru textured polygons. Actually what I'm doing is a fade in effect, and it works great as long as I don't load/bind the textures. So it's smooth when its just a plain white polygon with the alpha values changing over time, and I get a beautiful fade in effect. But once I load and apply that texture...it ends up being black for a little bit, and then showing up textured alright, but completely opaque. No fading at all. Whats odd is, is that if I put the loadtexture part in my onDrawFrame prior to drawing, it works but halfass, like at 1 or 2 frames a second, which obviously is not what i should be doing cause it's like reloading the same textures over and over every frame rather than actually binding them. Am I missing something here? Here's my texture part of the code, the other parts aren't that relevant, but it must be a setting:



package com.example.bosskillers;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;

import android.opengl.GLU;
import android.opengl.GLSurfaceView.Renderer;

import android.util.Log;
//import android.widget.Toast;

public class OpenGL_Renderer implements Renderer 
	private Polygon polygon = null;
	private Context context = null;
	private float Fade;
	private float tempFade;
	private int Frame_Count;
	private int Get_Frames_Per_Second;
	private long Milliseconds;
	public OpenGL_Renderer(Context context)
		this.context = context;
		polygon = new Polygon();
	public void onDrawFrame(GL10 gl) 
			if(Intro.Blizzard_Logo.Enabled == true)
				Intro.Blizzard_Logo.Time = (double)(System.currentTimeMillis() - Intro.Blizzard_Logo.Milliseconds) / 1000.0f;
				tempFade = (float)(Intro.Blizzard_Logo.Speed * Intro.Blizzard_Logo.Time);
				if(tempFade >= 255.0f)
					tempFade = 255.0f;
					Intro.Blizzard_Logo.Enabled = false;
			Fade = tempFade / 255.0f;
			gl.glTranslatef(0.0f, 0.0f, 0.0f);
			polygon.draw(gl, 0, 1.0f, 1.0f, 1.0f, Fade);
			gl.glTranslatef(MainActivity.Height, 0.0f, 0.0f);
			polygon.draw(gl, 1, 1.0f, 1.0f, 1.0f, Fade);

			if (System.currentTimeMillis() - Milliseconds >= 1000)
				Get_Frames_Per_Second = Frame_Count;
				Log.d("test", String.valueOf(Get_Frames_Per_Second));
				//Toast.makeText(MainActivity.Get_Application_Context(), String.valueOf(Get_Frames_Per_Second), Toast.LENGTH_SHORT).show();
				Frame_Count = 0;
				Milliseconds = System.currentTimeMillis();

	public void onSurfaceChanged(GL10 gl, int width, int height) 
		if(height == 0) height = 1;
	    gl.glDisable( GL10.GL_CULL_FACE );
	    gl.glDisable( GL10.GL_DEPTH_TEST );
		gl.glViewport(0, 0, width, height);
		//GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
		GLU.gluOrtho2D(gl, (float)0, (float)width, (float)height, (float)0);

	public void onSurfaceCreated(GL10 gl, EGLConfig config) 
		gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
		gl.glGenTextures(2, Polygon.textures_list, 0);
		polygon.loadTexture(gl, 0, this.context,R.drawable.blizzard_logo_1);
		polygon.loadTexture(gl, 1, this.context,R.drawable.blizzard_logo_2);
		Milliseconds = System.currentTimeMillis();


package com.example.bosskillers;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.opengl.GLUtils;

public class Polygon 
	private FloatBuffer vertexBuffer;	// buffer holding the vertices
	private FloatBuffer textureBuffer;
	public static int texture1;
	public static int texture2;
	public static int[] textures_list = new int[2];
	private Bitmap bitmap;
	public float texture[] =
		0.0f, 0.0f,
		1.0f, 0.0f,
		0.0f, 1.0f,
		1.0f, 1.0f
	public float vertices[] = 
			0.0f, 0.0f,  0.0f,		// V1 - first vertex (x,y,z)
			MainActivity.Height, 0.0f,  0.0f,	// V2 - second vertex
			0.0f, MainActivity.Height,  0.0f,	// V3 - third vertex
			MainActivity.Height, MainActivity.Height,  0.0f	// V4 - forth vertex
	public Polygon() 
		// a float has 4 bytes so we allocate for each coordinate 4 bytes
		ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
		// allocates the memory from the byte buffer
		vertexBuffer = byteBuffer.asFloatBuffer();
		// fill the vertexBuffer with the vertices
		// set the cursor position to the beginning of the buffer
		byteBuffer = ByteBuffer.allocateDirect(texture.length * 4);
		textureBuffer = byteBuffer.asFloatBuffer();
	public void loadTexture(GL10 gl, int index, final Context context, final int resourceId)
		final Options options = new Options();
	    options.inScaled = false;
		// loading texture
		bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
		//InputStream is = context.getResources().openRawResource(R.drawable.jake);

	    //Bitmap bitmap = null;
	    //try {
	    //    bitmap = BitmapFactory.decodeStream(is);

	    //} finally {
	    //    //Always clear and close
	    //    try {
	    //        is.close();
	    //        is = null;
	    //    } catch (IOException e) {
	    //    }
		// ...and bind it to our array
		gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_list[index]);
		// create nearest filtered texture
		// Use Android GLUtils to specify a two-dimensional texture image from our bitmap 
		GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
		// Clean up
	public void draw(GL10 gl, int index, float Red, float Green, float Blue, float Alpha) 

		// Point to our vertex buffer
		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
		gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
		gl.glColor4f(Red, Green, Blue, Alpha);
		gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_list[index]);
		// Draw the vertices as triangle strip
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
		//Disable the client state before leaving
		gl.glDisableClientState (GL10.GL_VERTEX_ARRAY);