C++ Winsock Networking Tutorials [04-24-2017]

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Pindrought
Posts: 432
Joined: September 26th, 2013, 4:57 pm
Location: Kentucky
Contact:

C++ Winsock Networking Tutorials [04-24-2017]

Post by Pindrought » February 22nd, 2016, 6:22 am

Note: Topic will be updated each time thread is updated.

Link to Tutorial Playlists

[Beginner Winsock Networking with Blocking Sockets]: https://www.youtube.com/playlist?list=P ... 7NzSlxlTKx

[Winsock Nonblocking Sockets]: https://www.youtube.com/playlist?list=P ... XR7-DDCNbX

Tutorial 1
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=AjG4jcVn6QE
Description:
How to create a server and a client.
How to connect to a server with the client.
How to receive 256 character message from server as the client.

Solution Link: http://www.mediafire.com/download/6i36x ... rial_1.rar
Tutorial 2
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=Plv7QdLkNQk
Description:
How to extend server to allow more than one client.
Allow clients to send messages to each other.

Solution Link: http://www.mediafire.com/download/brew8 ... rial_2.rar
Tutorial 3
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=YPCpUz5nTK0
Description:
How to change server and client to be able to process messages that are not exactly 256 characters (256 bytes) in size.

Solution Link: http://www.mediafire.com/download/d38ls ... rial_3.rar
Tutorial 4
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=Yz275L8HRts
Description: Set up the client and server to be able to process different types of packets.
Solution Link: http://www.mediafire.com/download/aozt1 ... rial_4.rar
Tutorial 5
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=wqRdELNi3z4
Description: Set up functions for receiving packet, int, and string and for sending packet, int and a string. Be able to check if there is a connection issue.
Solution Link: http://www.mediafire.com/download/628dr ... rial_5.rar
Tutorial 6
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=hyNF3m-JlN4
Description: Create Client and Server class to make the program more object oriented. Also adding more error checking for when things go wrong.
Solution Link: http://www.mediafire.com/download/g48be ... rial_6.rar
Tutorial 7
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=wkTwx4FOElg
Description: Handling partially sent/received packets.
Solution Link: http://www.mediafire.com/download/gcd4n ... rial_7.rar
Tutorial 8
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=Utq5KYf ... e=youtu.be
Description: Big Endian vs Little Endian - What is it and how to handle it?
Solution Link: http://www.mediafire.com/download/5dab8 ... rial_8.rar
Tutorial 8 Fix
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=n4Clp-7HX5M
Description: Reviews fix made to Tutorial 8.rar that I forgot to include in the video. Applies endianness that we learned in Tutorial 8 to the Send/Get Packet Type functions.
Tutorial 9 Pre-Tutorial Review
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=DZ3g3FV9wQo
Description: Reviews how to read/write from binary files using std::ifstream and std::ofstream and how to copy a file using these techniques. These will be used in Tutorial 9 for sending a file from the server to the client.
Tutorial 9
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=9jLhDYtyA7c
Description: How to send a file from the server to the client?
Solution Link: http://www.mediafire.com/download/wpzj6 ... rial_9.rar
Tutorial 10 Pre-Tutorial Review #1 (Linked Lists)
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=JoqW88fNDCU
Description: Reviews a brief summary over how to use linked lists. We will use these in tutorial 10 when we begin implementing a packet manager to synchronize our outgoing packets.
Solution Link: http://www.mediafire.com/download/7836e ... ration.rar
Tutorial 10 Pre-Tutorial Review #2 (Mutexes)
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=aN--UP7 ... e=youtu.be
Description: Reviews a brief summary over how to use mutexes. We will use these in tutorial 10 when we begin implementing a packet manager to synchronize our outgoing packets.
Solution Link: http://www.mediafire.com/download/ottqm ... ration.rar
Tutorial 10 Pre-Tutorial Demonstration (Vector vs Linked List Speed)
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=jEOxIgbtSLQ
Description: Demonstrates the speed difference in using a vector of packets and a linked list of packets.
Solution Link: http://www.mediafire.com/download/7ddsg ... ration.rar
Tutorial 10 Pre-Tutorial Demonstration [Fixed] (Vector vs Linked List vs Queue Speed)
Spoiler:
Youtube Link: https://youtu.be/GEYrVhaD08I
Description: Demonstrates the speed difference in using a vector of packets, linked list of packets, and a queue of packets.
Solution Link: http://www.mediafire.com/download/7ddsg ... ration.rar
Tutorial 10
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=Yxvri-W ... e=youtu.be
Description: Implementing packet manager into server.
Solution Link: http://www.mediafire.com/download/zlco4 ... ial_10.rar
Tutorial 11
Spoiler:
Youtube Link: https://youtu.be/Ut6pi9ZmrVU
Description: Change server to use a vector of connections to allow more than 100 connections at once and address the issue of sending data to users that have already disconnected. (Note: Server most likely wont be able to handle that many clients properly using blocking sockets - this will be addressed later)
Solution Link: http://www.mediafire.com/download/7kd6y ... ial_11.rar
Set up server to have other people connect
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=xikq1pO ... 7NzSlxlTKx
Description: Explains how set up server/client so that other computers on router can connect or other computers from remote locations can connect to your server.
Solution Link: None
Tutorial 12
Spoiler:
Youtube Link: https://youtu.be/be09jpq0Mlw
Description: Modify server to use packet manager to send files.
Solution Link: http://www.mediafire.com/file/011yhs11b ... ial+12.rar
Tutorial 13
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=zdQDHCjJ7YQ
Description: Many changes. Client now uses packet manager, changed how packet manager works to use shared_ptr of Packets, changed how packets worked to use vector of bytes instead of a char * to the buffer, cleaned up code, added m_ prefix to member variables, used const where applicable, changed from CreateThread to std::thread, no longer using deprecated functions, removed unnecessary includes, using shared_lock now for packetsender and processpacket, no longer using strange connection management, etc.
Solution Link: http://www.mediafire.com/file/cx1mxfl0f ... ial_13.rar

NONBLOCKING TUTORIALS LISTED BELOW

Tutorial 1
Spoiler:
Youtube Link: https://youtu.be/M4VFJ0hxPDg
Description: Create basic nonblocking server that can accept connections and attempts to receive 4 bytes of data and display the data using std::cout. Can also handle if a client disconnects. Only utilizes the readfds FD_SET.
Solution Link: http://www.mediafire.com/file/y19zuyfe6 ... rial_1.rar
Tutorial 2
Spoiler:
Youtube Link: https://youtu.be/2Sb359eZdWA
Description: Add write and except FD_SET's and handling for them.
Solution Link: http://www.mediafire.com/file/oe9k5wq44 ... rial_2.rar
Tutorial 3
Spoiler:
Youtube Link: https://youtu.be/ldS885D97ZU
Description: Create nonblocking client. [Note: Client does not handle if server loses connection, but will be addressed in tutorial 3.5]
Solution Link: http://www.mediafire.com/file/wov8fs80v ... rial_3.rar
Tutorial 3.5
Spoiler:
Youtube Link: https://www.youtube.com/watch?v=9zB_xb9SleQ
Description: For nonblocking client simulator, add functionality to detect if connection is lost to the server.
Solution Link: http://www.mediafire.com/file/v2f88hjdq ... al_3.5.rar
Tutorial 4
Spoiler:
Youtube Link: https://youtu.be/P1fLN6AKLPE
Description: Add handling for partial send/recv's, add TCPConnection class to store information about the current connection. Briefly review the process for how we will be handling sending/recv'ing differently on nonblocking on blocking.
Solution Link: http://www.mediafire.com/file/t5xght6gp ... rial_4.rar
Last edited by Pindrought on April 24th, 2017, 5:28 pm, edited 46 times in total.
PM me if you need to contact me. Thanks to all the helpful people on this forum especially to Chili.

adabo
Posts: 154
Joined: October 27th, 2012, 3:28 am
Location: Houston, Texas

Re: C++ Winsock Networking Tutorials [2-22-2016]

Post by adabo » February 22nd, 2016, 3:23 pm

Will definitely be keeping an eye on this. Thank you kindly!

adabo
Posts: 154
Joined: October 27th, 2012, 3:28 am
Location: Houston, Texas

Re: C++ Winsock Networking Tutorials [2-22-2016]

Post by adabo » February 22nd, 2016, 3:47 pm

Hmm, so I just watched the first tut and I'm wondering, is winsock what we use to send data in multiplayer games? I have no idea about networking, so I'm at your mercy of knowledge.

Pindrought
Posts: 432
Joined: September 26th, 2013, 4:57 pm
Location: Kentucky
Contact:

Re: C++ Winsock Networking Tutorials [2-22-2016]

Post by Pindrought » February 22nd, 2016, 4:34 pm

adabo wrote:Hmm, so I just watched the first tut and I'm wondering, is winsock what we use to send data in multiplayer games? I have no idea about networking, so I'm at your mercy of knowledge.

Winsock is a library used to send data over sockets for Windows platforms, so to answer your question yes. You will want to use a different networking library however for linux or apple systems since I don't think Winsock is cross platform.
PM me if you need to contact me. Thanks to all the helpful people on this forum especially to Chili.

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: C++ Winsock Networking Tutorials [2-22-2016]

Post by LuisR14 » February 22nd, 2016, 6:54 pm

but winsock contains functions that are cross platform, ..actually, winsock has its own functions which the cross platform functions are equivalents of

(pretty much you can create same app with such functions, only exception is those WSAStartup and WSACleanup functions, which is easy to exclude for non-windows apps anyways)
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

adabo
Posts: 154
Joined: October 27th, 2012, 3:28 am
Location: Houston, Texas

Re: C++ Winsock Networking Tutorials [2-22-2016]

Post by adabo » February 22nd, 2016, 6:56 pm

Oh wow, really? So windows games like Call of Duty, Age of Empires, WoW, all use winsock?

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: C++ Winsock Networking Tutorials [2-22-2016]

Post by LuisR14 » February 22nd, 2016, 7:14 pm

yea most likely :)
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

Pindrought
Posts: 432
Joined: September 26th, 2013, 4:57 pm
Location: Kentucky
Contact:

Re: C++ Winsock Networking Tutorials [2-22-2016]

Post by Pindrought » February 22nd, 2016, 7:15 pm

LuisR14 wrote:but winsock contains functions that are cross platform, ..actually, winsock has its own functions which the cross platform functions are equivalents of

(pretty much you can create same app with such functions, only exception is those WSAStartup and WSACleanup functions, which is easy to exclude for non-windows apps anyways)
Thanks for the clarification LuisR14. I wasn't really sure myself of how it worked when it came to cross platform implementations.
PM me if you need to contact me. Thanks to all the helpful people on this forum especially to Chili.

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: C++ Winsock Networking Tutorials [2-22-2016]

Post by LuisR14 » February 22nd, 2016, 7:18 pm

no problemo :)
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: C++ Winsock Networking Tutorials [2-22-2016]

Post by MrGodin » February 22nd, 2016, 8:38 pm

Hey, nice to see you doing these again :). I have a question, does the lib work on x64 or do you need a different lib ?.
Curiosity killed the cat, satisfaction brought him back

Post Reply