• 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
savail

WINSOCK - connection refused to localhost

6 posts in this topic

hey,
I was following this tutorial [url="http://www.win32developer.com/tutorial/winsock/winsock_tutorial_1.shtm"]http://www.win32deve...tutorial_1.shtm[/url] and finally wanted to test whole code:
[CODE]
#include <iostream>
#include <winsock2.h>
#include <errno.h>
#pragma comment(lib,"ws2_32.lib")
int main()
{
// Initialise Winsock
WSADATA WsaDat;
if(WSAStartup(MAKEWORD(2,2),&WsaDat)!=0)
{
std::cout<<"Winsock error - Winsock initialization failed\r\n";
WSACleanup();
system("PAUSE");
return 0;
}

// Create our socket
SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(Socket==INVALID_SOCKET)
{
std::cout<<"Winsock error - Socket creation Failed!\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
// Resolve IP address for hostname
struct hostent *host;
if((host = gethostbyname("localhost"))==NULL)
{
std::cout<<"Failed to resolve hostname.\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
// Setup our socket address structure
SOCKADDR_IN SockAddr;
SockAddr.sin_port=htons(8888);
SockAddr.sin_family=AF_INET;
SockAddr.sin_addr.s_addr=*((unsigned long*)host->h_addr);
// Attempt to connect to server
if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr)) == -1)
{
std::cout<<"Failed to establish connection with server\r\n"<<WSAGetLastError();
WSACleanup();
system("PAUSE");
return 0;
}
// Display message from server
char buffer[1000];
memset(buffer,0,999);
int inDataLength=recv(Socket,buffer,1000,0);
std::cout<<buffer;
// Shutdown our socket
shutdown(Socket,SD_SEND);
// Close our socket entirely
closesocket(Socket);
// Cleanup Winsock
WSACleanup();
system("PAUSE");
return 0;
}
[/CODE]
However, I'm getting error 10061 all the time, which means connection refused. I'm totally confused with this winsock. All tutorials are either obsolete, only unix or incomplete... I tried switching off my firewall and anti vir but that didn't help. Does anyone know why can't I connect to my localhost? I would be really garteful for help! And please don't hesitate to provide any advice as I'm really totally inexperienced with network programming. Edited by savail
0

Share this post


Link to post
Share on other sites
I've got no idea. I don't understand even if the port can be random or how to select a port to put there. Whole this code is from a tutorial and it's said there that I should be able to connect to localhost with it ;/
0

Share this post


Link to post
Share on other sites
If there is no program listening on that port, then that error code is expected. Either you need to write a server which listens on 8888 and have it running while starting the client or you need to find some program that listens on a port and sends a text string to any connecting client.

Edit: Back when I learned about networking I used [url=http://beej.us/guide/bgnet/output/html/multipage/index.html]Beej's Guide to Network Programming[/url]. To my knowledge, there still isn't anything better around for the bare bones. Edited by BitMaster
1

Share this post


Link to post
Share on other sites
ah true. Next lesson in thsi tut was creating a server... Though there was nothing said that in order to connect to localhost you need to create a server first and run it. For some really new users it might not be so obvious. Thanks for your help
-1

Share this post


Link to post
Share on other sites
Hi savail, I am the author of the site.

Appologies, I should have been clearer.

Although, it does state on the first line of the tutorial;

[quote]This tutorial is to designed to get a feel for the most basic Winsock model, the blocking socket. By the end you will have a working client. The server can be found in Tutorial 2.[/quote]

But, yes, a client will always need a server to connect to. I am glad you have realised that tutorial 2 is the compliment of tutorial 1 (As is the trend through out the rest of the site). Edited by lonewolff
0

Share this post


Link to post
Share on other sites
hey, sorry I reply so late. I should have been more careful, didn't notice that line while reading it for a first time. Anyway your site has helped me a lot. It contains one of most recent tutorials on winsock. I have read plenty of tutorials before this on your site, but your has helped me most in understanding how TCP works. Good job with those tutorials ^^. Hope there will be more of them!
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