Jump to content
xisto Community
Sign in to follow this  
ghostrider

An Indepth Look At The Winsock Control Part I - The Basics

Recommended Posts

I wrote this just today. Please tell me if its written well. If you guys like it I'll continue you to write more.An Indepth Look at the Winsock ControlPart I - The BasicsWho This Documentation Is For: This documentation on the Winsock control is for any Visual Basic programmer that wants to learn about communication between two or more computers. Communication between computers was something I found fun to learn, and also teachs many other key concepts like string parsing and control arrays. I recommend that you have some expierence with Visual Basic, enough that you are able to handle variables and know what the functions Chr(), Asc(), Mid(), and other common functions do. You should also know the difference between functions and subs, and how to return the result from a function. You should also understand how variables work. I will add comments on any code that might not make sense.What is covered in Part I: In Part I, I will go over the two different protocols (ways that data is sent and how the connections are set up), what IP addresses are, and what ports are. No actual code is written in this part, however by the end we will have made a fully useable chat application that is capable of chat between 2 or more than 2 different people.The Two Different Protocols: Using the Winsock control there are two different protocols, or two different ways of connecting to another computer and sending data. They are named Transfer Control Protocol (TCP), which is the default protocol if you do not define one. The other much less used protocol is called User Datagram Protocol (UDP). There are many technical differences between TCP and UDP, but they do not affect us. The difference that is important that we need to concern ourselves with is this, TCP requires a connection between, and UDP does NOT.How TCP connects to computers: In a TCP connection, one computer is the server. The server 'listens' for incoming requests, and then either 'accepts' them or closes the connection. The client(s) 'connect' to the server. In order for you to make the connection, the client(s) need to know either the host name or IP address of the server, and the port that the server is listening on. TCP is very much like a telephone, the client(s) call the server, and the server picks up the phone. After the connection has been established, both computers can send data back and forth.How UDP works: Very unlike TCP, UDP does not need a connection. UDP does not have a server or a client. Each computer needs to know the port the computer is transfering data through, and the IP address of the other. UDP is suitable for sending small amounts of data between computers. UDP is like passing a note in class, no connection is needed like a telephone.What are IP Addresses and Ports: An IP address is like the address of your house. Each person has a different one, and it identifies you. An IP address has a format like this xxx.xxx.xxx.xxx. Not all of the x's have to be used in each set of x's. The 4 x sets can be from the values of 0 to 255. IP addresses within Local Area Networks always start with 192.xxx.xxx.xxx or 172.xxx.xxx.xxx or even 10.xxx.xxx.xxx. It is important that you understand that computers can have more than one IP address. For example right now, my computer has two, one of them being the one that it has inside of my local area network (the network I have in my house) and one for the internet, that other computers outside of my LAN know my computer as. Each computer 65536 ports, number from 0 to 65535. Ports were designed so that data doesnt come through all at once, it can be seperated. HTTP (Hypertext Transfer Protocol) or more commonly know as web pages uses Port 80, and FTP (File Transfer Protocol) uses port 21. These ARE NOT different protocols that the Winsock control usees. Don't get confused by that. HTTP and FTP both happen to work using TCP.

Edited by ghostrider (see edit history)

Share this post


Link to post
Share on other sites

Nice work. Keep it coming. You have a very nice approach to simplifying the material of a complex topic. I look forward to seeing more information from you on this issue. And why, exactly is it in Quote tags?

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  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.