• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Slider_SLO

SDL.net

10 posts in this topic

Hey

I just wanna ask if anyone knows for some SDL.net tutorials for basic/beginners++, i allready went through top tutorials that I could find but still I have some problems...

Im having a problem that my client sends only one package to the server and cant send any other date and doesnt want to send same package aswell, its like the client locks down after the first package... Any ideas?

0

Share this post


Link to post
Share on other sites
I made a mistake im not sending packages only strings and im using TCP, I know the basics of TCP/UDP and how it works...
Well my client app waits for the input and to send to the server and i can send the first string without any problems but after that I cant send anything else. It looks like that socket I created locks down after the first sting or something like that. Edited by Slider_SLO
0

Share this post


Link to post
Share on other sites
SDLNet_TCP_Recv will wait if there is no data to read. Could that be it?
0

Share this post


Link to post
Share on other sites

Im using SDLNet_TCP_Recv function in a loop to wait for the incoming string and it prints me out that string that comes in and im using function SDLNet_TCP_Send on the client side to send that string from client to server.

After i send my first string from client to server app everything is fine for the first string but for only one string for any other strings I want to send to the server I have to restart my client app.

0

Share this post


Link to post
Share on other sites

For the moment im not using it since I only created one way communication from client to server. Want to get this done at first before i move on to 2way communicating betwen multiple clients...

0

Share this post


Link to post
Share on other sites

Sounds like you might have a logic problem somewhere or perhaps aren't checking error codes or some such. But without seeing any code, all anyone can do is guess. It would be helpful if you post some code relevant to the problem.

0

Share this post


Link to post
Share on other sites

This is my server app, it starts up SDL makes window etc. and then waits for the incoming data....

 

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_net.h>
#include <cstring>
//SERVER--------------
int main(int argc,char** argv)
{
        freopen("CON","w",stdout);
        int running = 1;
        char buffer[512];
        SDL_Init(SDL_INIT_EVERYTHING);
        SDLNet_Init();
        SDL_WM_SetCaption("Server", NULL);
        SDL_Surface *screen, *background;
        screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
        background = SDL_DisplayFormat(SDL_LoadBMP("background.bmp"));
        

        IPaddress ip;
        SDLNet_ResolveHost(&ip,NULL,1234);

        TCPsocket server=SDLNet_TCP_Open(&ip);
        TCPsocket client;


        SDL_BlitSurface(background, NULL, screen, NULL);
        SDL_Flip(screen);

       
        

        while(running)
        {
                SDL_Event event;
                while(SDL_PollEvent(&event)) {
                       switch(event.type) {
                                case SDL_QUIT:
                                        running = 2;
                                        break;
                       }
                }

             client=SDLNet_TCP_Accept(server);
                if(client)
                {
                        if (SDLNet_TCP_Recv(client, buffer, 512) > 0)
                                    {
                                       printf("From Client: %s\n", buffer);
                                       SDLNet_TCP_Close(client);
                                        }
                       
                        
                        //SDLNet_TCP_Send(client,text,strlen(text)+1);
                        //SDLNet_TCP_Close(client);
                       //break;
                }

             if (running==2)
             {

             SDLNet_Quit();
             SDL_Quit();
                 }
            }

        SDL_FreeSurface(background);
        SDL_FreeSurface(screen);
       


        SDLNet_TCP_Close(server);


        SDLNet_Quit();
        SDL_Quit();


}
 

 

 

 

And this client starts window waits for the input to send string to server...

 

 

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_net.h>
#include <cstring>
//---------CLIENT----
int main(int argc,char** argv)
{
        SDL_Init(SDL_INIT_EVERYTHING);
        SDLNet_Init();
        //init graficne stvari
        SDL_Surface *screen, *background;
        screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
        background = SDL_DisplayFormat(SDL_LoadBMP("background.bmp"));
        
        bool b[4] = {0,0,0,0};
        bool running = true;
        char buffer[512];
        char* mesg="aaa aa a aa";
        char* mesg2="bbbb bb b";
        char* mesg3="cc ccccc c";
        char* mesg4="d d dddd d";
        
        freopen("CON","w",stdout);

        IPaddress ip;
        SDLNet_ResolveHost(&ip,"127.0.0.1",1234);

        
        SDL_BlitSurface(background, NULL, screen, NULL);
        SDL_Flip(screen);

        
        TCPsocket client=SDLNet_TCP_Open(&ip);



        while(running)
        {
            SDL_Event event;
                    while(SDL_PollEvent(&event)) {
                            switch(event.type) {
                                case SDL_QUIT:
                                    running = false;
                                    SDL_Quit();
                                    break;
                                case SDL_KEYDOWN:
                                    switch(event.key.keysym.sym)
                                    {
                                        case SDLK_w:
                                                b[0] = 1;
                                                break;
                                        case SDLK_a:
                                                b[1] = 1;
                                                break;
                                        case SDLK_s:
                                                b[2] = 1;
                                                break;
                                        case SDLK_d:
                                                b[3] = 1;
                                                break;
                                    }
                                    break;
                                case SDL_KEYUP:
                                     switch(event.key.keysym.sym)
                                     {
                                                case SDLK_w:
                                                        b[0] = 0;
                                                        break;
                                                        case SDLK_a:
                                                        b[1] = 0;
                                                        break;
                                                case SDLK_s:
                                                        b[2] = 0;
                                                        break;
                                                case SDLK_d:
                                                        b[3] = 0;
                                                        break;

                                     }
                                        
                            
                            
                            }
            if(b[0]){
            SDLNet_TCP_Send(client,mesg,strlen(mesg)+1);
            SDLNet_TCP_Close(client);
                }
            if(b[1]){
            SDLNet_TCP_Send(client,mesg2,strlen(mesg2)+1);
            SDLNet_TCP_Close(client);
                }
            if(b[2]){
            SDLNet_TCP_Send(client,mesg3,strlen(mesg3)+1);
            SDLNet_TCP_Close(client);
                }
            if(b[3]){
            SDLNet_TCP_Send(client,mesg4,strlen(mesg4)+1);
            SDLNet_TCP_Close(client);
                }
                            
        }

                
            }
    //    char text[10000];
        


    
        //while(SDLNet_TCP_Recv(client,text,10000))
        //        std::cout << text;
        
        

        
        SDL_FreeSurface(screen);
        SDL_FreeSurface(background);
        
        SDLNet_TCP_Close(client);
        SDLNet_Quit();
        SDL_Quit();
}
 

0

Share this post


Link to post
Share on other sites
The problem is that you close the client socket, both on the client and on the server, and then you try to use that socket again. After the socket has been closed you can't use it to send or receive. You would have to reconnect to the server each time you send or keep the connection open the whole time.
0

Share this post


Link to post
Share on other sites

ups that was a msitake i did when i was trying out something so just ignore those SDLNet_TCP_Close(client); functions, my original code is without em...

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0