Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

222 Neutral

About methinks

  • Rank

Personal Information

  • Interests
  1. Thanks for the help. You were right, it was the browser. I just want to clarify the first point; If I understand correctly you just need a different place or structure to hold the sockets, but you can still use select to call them the same as before? As for the second point, I did have error checking in my original code, I just left it out of my example code to keep it smaller and easier to read... maybe I left out a bit too much.
  2. I'm trying to write a simple server application using Winsock2. I have a socket listening on port 80 (for http traffic). When I run the program and use my browser to connect to, the server receives the connection and displays it as expected. New Connection Recieved message: GET / HTTP/1.1 Host: Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 DNT: 1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9 The problem comes when I try to close the socket. I'm using the following two commands: closesocket(currentSocket); FD_CLR(currentSocket, &socketList); When I do this, the program keeps repeating the output as if it was getting the same request over and over. If I remove either of these commands it only displays the output once, as it should. The complete source code is as follows. This is a simplified version of the code that will duplicate the behavior, so I've omitted certain checks for clarity. #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif // !WIN32_LEAN_AND_MEAN #pragma comment(lib, "ws2_32.lib") #include <WinSock2.h> #include <iostream> void runTest() { ////// SETUP /////// const int LISTENING_PORT = 80; const int BUFFER_SIZE = 4098; WSADATA wsa; sockaddr_in listeningAddress; listeningAddress.sin_family = AF_INET; listeningAddress.sin_port = htons(LISTENING_PORT); listeningAddress.sin_addr.S_un.S_addr = INADDR_ANY; WSAStartup(MAKEWORD(2, 2), &wsa); SOCKET listeningSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); bind(listeningSocket, (sockaddr*)&listeningAddress, sizeof(listeningAddress)); listen(listeningSocket, SOMAXCONN); fd_set socketList; FD_ZERO(&socketList); FD_SET(listeningSocket, &socketList); ////// MAIN LOOP /////////// bool isRunning = true; while(isRunning) // endless loop, normally has interupt mechanism { fd_set socketListCopy = socketList; int socketCount = select(0, &socketListCopy, nullptr, nullptr, nullptr); for (int i = 0; i < socketCount; i++) { SOCKET currentSocket = socketListCopy.fd_array[i]; if (currentSocket == listeningSocket) { std::cout << "New Connection\n"; SOCKET client = accept(listeningSocket, nullptr, nullptr); FD_SET(client, &socketList); } else { char buffer[BUFFER_SIZE]; memset(buffer, 0, BUFFER_SIZE); int bytesIn = recv(currentSocket, buffer, BUFFER_SIZE, 0); std::cout << "\nRecieved message:\n" << buffer << '\n'; // Using the following two lines causes the output to loop closesocket(currentSocket); FD_CLR(currentSocket, &socketList); } } } WSACleanup(); }
  3. I'm trying to learn how to write plugins (OSX Yosemite). Everything compiles and runs properly, the shared object is loaded, but function in the shared object doesn't execute.   All the files remain in the same directory.   The host application, compiled as follows: g++ -ldl -o Host Host.cpp // Host.cpp   #include <iostream> #include <dlfcn.h> using namespace std; int main(int argc, char* argv[]) {     void * plugin = dlopen("Plugin.mod", RTLD_NOW);     if(plugin == nullptr)     {         cout << "Error opening file" << endl;     }     else     {         cout << "File open, attempting to access function" << endl;         dlerror();         dlsym(plugin, "run"); // This is where the line "Plugin Running" should be printed to the console         char * errMsg = dlerror();         if(errMsg)         {             cout << "Unable to access function" << endl;         }         else         {             cout << "Success: " << endl;         }         dlclose(plugin);     } } The plugin that gets called g++ -fPIC -c Plugin.cpp g++ -shared -o Plugin.mod Plugin.o // Plugin.cpp #include <iostream> using namespace std; extern "C" void run() {     cout << "Plugin running" << endl; } and the output: File open, attempting to access function Success:   Is this a problem with the code, or the compilation?
  4. Thanks for the feedback. I'll look into instanceof, it looks like it will do what I need for the type, though I'll still face the same problem for other pieces of data (Such as UUID).   To be honest, I don't know quite yet, the id will probably be used as keys in a HashMap, but I haven't gotten that far yet. Partly I'm just trying to understand the language itself.   Tried this, but I got the error "Duplicate Function"   For now I'll go with this; not as clean as I'd like, but functional class ItemA extends Item {   public static final String id = "ITEM_A";      @Override   public String getId()   {     return id;   } } then call ItemA.id or i.getId()
  5. I'm coming from C++, trying to learn Java. The issue is that Java doesn't allow overriding of static functions.   In this case, I would like each class that inherits from a parent (let's call it the Item class) to have an identifier that get by calling getId().   class Item {   abstract String getId(); } class ItemA extends Item {   String getId()   {     return "ITEM_A";   } } The thing is that I want to be able to call getId without having to instantiate the class, so that I can do something like this:   void foo(Item i) {   if(i.getId() == ItemA.getId())   {     //Do Something   } } Java doesn't allow abstract static functions, so I'm left with defining non-abstract static functions. As a result, the above function doesn't work, because i.getId() returns the Parent object's id, not that of the child object.   Are there any ways around this, or what would be a better way of dealing with it?  
  6. It doesn't look like a namespace issue, because they are showing the same namespace (a::A::A) Could it be that the project is trying to compile the same class multiple times? (Do you have an include guard in the header?)
  7. Ok, so a more generic version of the question: what is the best way to share the data between different classes that are completely un-related?
  8. I want to add a central data manager to my project, so that different classes can share data. It will also act as a map to avoid doubling up on resources.   [attachment=15516:layout1.png]   I figure that there are 3 ways I can do this: create the manager as a global (EVIL) pass the manager to each class as it is created (UGLY) create the manager as a singleton Every post I see says to avoid singletons, but is this a situation that breaks the rule, or is there a better solution?   Also, the graphic data above is just one type of data; realistically there will be many data types. To avoid having a whole mess of singletons, I would create a central data manager that has a factory class for each type:   [attachment=15517:layout2.png]   Oh yeah, I'm doing this in C++, but the concepts should apply to most languages
  9. methinks

    Is a mesh a 3d model?

    The mesh is the data describing the points that make up the object (This includes faces and edges). This is just one small part of the model.   "Model" is a generic term. It means any data related to drawing a 3d item onto the screen. Exactly what data this includes depends on the program or file format. In some case it might just be the mesh, although usually it also includes some of the following: Material - the colours, shading models, and other things that determine how to apply lights and rendering Textures - the images that are mapped onto the mesh UV - co-ordinates that determine how textures are applied to the mesh vertex groups - used to break the model into smaller chunks for special purposes bones / armatures - used to link parts of the mesh to specific parts of animations animations - how the mesh moves ... the list goes on, depending on what you're trying to do with the mesh.
  10. methinks

    Making Blender files take up less space?

    The difference is what actually gets saved. The 3ds file only saves the model data itself (geometry, materials, etc) while the blender file contains structures explaining the data as well (the so-called DNA structure) that guarantees both forward and backward compatibility. Add to this the workspace setup (tool settings, layouts, preferences, etc), the blender file actually contains far more data. (To be very specific, the blender file is a direct dump of the internal data structure, while the 3ds is an optimized format to store only very specific data)
  11. I know that in directx, the 3d stereo works by shifting the camera and rendering two different images. I was wondering if there is any way to write directly to the buffer, to display different textures to each eye. This would be useful for having 3d background images, or in my case, writing a 3d image viewer. I know this can be done in opengl by accessing the quad buffer, but I haven't been able to find any documentation for directx. If it helps any, I'm working with nvidia cards. Thanks
  12. methinks

    MVC pattern question

    Thanks for the reply. Just a couple of questions/comments. How is your example different from the second example I gave, where the model does the processing. Quote:Original post by Antheus I don't see all that much use between following such designs too strictly in non-CRUD applications. Each of such frameworks ends up with some fatal flaw which requires horrible hacks to work around. Thanks for the input. Right now, I'm just trying to understand the design, to see if it'll do what I need. Quote:Original post by Antheus Paint application works on Image. Just about every OS provides all the required functionality out of box, from drawing, editing to input handling. There is not much need for abstractions. Same applies to many other problems. MVC makes only sense if building some well-tiered framework where certain functionality may deliberately not be available. The paint application was just an example, but even so, I'd like to keep some separation, to make it easier to port between platforms.
  13. I'm trying to understand the MVC pattern, and I'm having difficulty figuring out where data processing takes place. Let's say I was building a paint program using MVC, which would be the better way to go? the user draws a line the line is sent to the controller the controller processes the line, turning it into an image the line image is sent to the model, which adds it to the existing image data the controller tells the view to update the view gets and displays the updated image data or the user draws a line the line is sent to the controller the controller sends the line data to the model the model processes the line, and adds it to the existing image data the controller tells the view to update the view gets and displays the updated image data Thanks
  14. I'm getting the following warning when I compile my program: ld: warning: directory '/Users/alex/Library/Frameworks' following -F not found Does anybody know what causes this error, and ideally how to fix it? I'm pretty sure that it started after I updated xCode via the automatic update (xCode 3.2.2). Normally I wouldn't worry about it too much, but I'm having a problem rendering in opengl (via SDL), and I want to make sure that it's not because of some linking error. Thank you
  15. not exactly a clean solution, but it seems to work... thanks!
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!