Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3670
Number of posts: 9122

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Basic Win9X Networking Info... Posted by Sephiroth on 11 Apr 2001 at 9:24 PM
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!

<br>-Sephiroth

Report
Re: Basic Win9X Networking Info... Posted by weicco on 11 Apr 2001 at 10:02 PM
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.\n");
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.



Report
Re: Basic Win9X Networking Info... Posted by weicco on 12 Apr 2001 at 4:58 AM
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.



Report
Re: Basic Win9X Networking Info... Posted by Sephiroth on 12 Apr 2001 at 8:50 PM
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!



-Sephiroth


Report
Re: Basic Win9X Networking Info... Posted by Murmandamus on 13 Apr 2001 at 3:45 AM
: 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!
:
:
:
: -Sephiroth
:
:

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



Report
Re: Basic Win9X Networking Info... Posted by Sephiroth on 13 Apr 2001 at 7:25 AM
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!



-Sephiroth


Report
Re: Basic Win9X Networking Info... Posted by Sephiroth2 on 13 Apr 2001 at 4:57 PM
: 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!
:
: -Sephiroth
:
Windows socket API is described in "Platform SDK", part of the Visual C++ documentation and available at www.microsoft.com



Report
Re: Basic Win9X Networking Info... Posted by Sephiroth on 14 Apr 2001 at 5:32 AM
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.



-Sephiroth





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.