Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Basic Win9X Networking Info...

SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
OK, I am now working on some multiplayer (coop only for now) aspects of my RPG. Could somebody give me the basics of opening a (port?/ip?) to send and recieve data with? Also, would I be able to use ReadFile/WriteFile with this object? I would even appreciate just a pointer to some networking basics under IPX and/or TCP for Win9X in C/C++. I first intend on making a simple chat program to get the basics of it, then I intend on adding file transfer ability, and once that is working, I'll start work on multiplayer and a possible shareware release. Thanks for the help everybody!


-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]

Comments

  • weiccoweicco Posts: 950Member
    TCP chat (very simple)
    Server:


    int main(void) {
    int fd, fd2;
    struct sockaddr_in sa;
    char buffer[100];

    if((fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    return -1;

    memset(&sa, 0, sizeof(sa));
    sa.sin_family = AF_INET;
    sa.sin_port = htons(some port - 8888 is good);
    sa.sin_addr.s_addr = htonl(INADDR_ANY);

    if(bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
    return -1;

    listen(fd, SOMAXCONN);

    while(1) {
    fd2 = accept(fd, (struct sockaddr *)&sa, (int *)sizeof(sa));
    recv(fd2, buffer, 100, 0);
    printf("%s", buffer);
    }
    return 0;
    }


    And client:


    int main(void) {
    int fd;
    struct sockaddr_in sa;
    char buffer[100];

    if((fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    return -1;

    memset(&sa, 0, sizeof(sa));
    sa.sin_family = AF_INET;
    sa.sin_port = htons(same as in server - 8888);
    sa.sin_addr.s_addr = inet_addr(Server IP);

    if(connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
    return -1;

    printf("Connected to server.
    ");
    while(1) {
    scanf("%s", buffer);
    send(fd, buffer, 100, 0);
    }
    return 0;
    }


    There's maybe some bugs and this is one way chat from client to server. If you are compiling this for Windows you must add WSAStartup(MAKEWORD(2, 2), &wsadata); this exam. works on Linux.



  • weiccoweicco Posts: 950Member
    Sending file through socket...

    Read file in buffer and give it's pointer and buffer size to send function:

    send(fd, (char *)pointer_to_buffer, len, 0);

    Pointer you give to send function can be any type, just cast it to char pointer.

    I'm sure there's better way to do this but can't figure out anything just now.



  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    I am doing a Win9X program. Thanks a ton for the info and I'll test it tomorrow morning. If I have any other probs I'll post. Thanks again!



    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]


  • MurmandamusMurmandamus Posts: 73Member
    : I am doing a Win9X program. Thanks a ton for the info and I'll test it tomorrow morning. If I have any other probs I'll post. Thanks again!
    :
    :
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]
    :
    :

    Hi,

    I have a comprehensive TCP/IP book in html format, which also has a chapter about sockets. If you want me to mail it to you, send me a message with your email adres. The zip file is 323KB (or I could email just the socket chapter, which is 12KB zipped).
    If you are using MFC, you might want to check out CAsyncSocket.

    Greets,
    Mark



  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    Yeah I'd REALLY appreciate that. Thanks! I wanna' learn as much about TCP/IP as possible, and that book will probably show me a ton more than I could figure out on my own. Just email it to me at: mazeops@hotmail.com

    Thanks again!



    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]


  • Sephiroth2Sephiroth2 Posts: 423Member
    : OK, I am now working on some multiplayer (coop only for now) aspects of my RPG. Could somebody give me the basics of opening a (port?/ip?) to send and recieve data with? Also, would I be able to use ReadFile/WriteFile with this object? I would even appreciate just a pointer to some networking basics under IPX and/or TCP for Win9X in C/C++. I first intend on making a simple chat program to get the basics of it, then I intend on adding file transfer ability, and once that is working, I'll start work on multiplayer and a possible shareware release. Thanks for the help everybody!
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]
    :
    Windows socket API is described in "Platform SDK", part of the Visual C++ documentation and available at www.microsoft.com



  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    I don't use visual anything. I feel that I lose a degree of control with the visual series, so I either use notepad, or the IDE (colored notepad!) in Borland. Most visual stuff I have tried doesn't wanna' work, but thanks for the info. I'll take a peek just to see what it has.



    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]


Sign In or Register to comment.