May 16, 2008

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

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > VB Programming

free web hosting

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

ghostrider
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 Control
Part I - The Basics

Who 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.

 

 

 


Reply

jlhaslip
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?

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. winsock control - 1447.75 hr back.
Similar Topics

Keywords : indepth, winsock, control, part, basics

  1. An Indepth Look At The Winsock Control (part Iii)
    Part III - The Coding Begins (0)
  2. An Indepth Look At The Winsock Control (part Ii)
    Part II - Events of the Winsock Control (0)
    An Indepth Look At the Winsock Control Part II - Events of the Winsock Control Stuff Covered in
    Part II: During this part of my tutorial I am covering all the Events of the Winsock tutorial.
    I'll also tell you how to add it to your project if you don't already know how. Be sure to
    have read my first tutorial, An Indepth Look At the Winsock Control Part I - The Basics The 7
    events of the Winsock Control: The Winsock Control is an event-driven control, meaning that whenever
    data is received or a computer wants to connect to ours, the control will call an even....
  3. Receiving Data With Winsock
    (1)
    I'm making a game server browser that, when loaded, runs through an array of IP's and sends
    a query to each of them - each of these IP's returns some data. When I receive this data, I want
    to parse it and store it in to the array I'm making a game server browser that holds all the
    game data in an array which is a custom data structure. The array holds information like IP, number
    of players, name of server etc. When the program loads, I want it to loop through the servers array
    and query all the IP's in there (the IP's are pre-set). The game serv....
  4. Winsock Problems!
    Can someone help me with it? (3)
    I'm working on creating a packet sniffer, but it's not exactly working. CODE Private
    Sub Form_Load() Winsock.RemoteHost = "1.0.0.27" Winsock.LocalPort = 0 Winsock.Listen
    Winsock1.RemoteHost = "cokestudios2.cokemusic.com" Winsock1.RemotePort = 80 Winsock1.Connect
    End Sub Private Sub Winsock_DataArrival(ByVal bytesTotal As Long) Dim data As String
    Winsock.GetData data Text1.Text = data + Text1.Text End Sub That's the code I'm using
    as of now, Winsock is the client and Winsock1 is the server. I'm extremely new....

    1. Looking for indepth, winsock, control, part, basics

Searching Video's for indepth, winsock, control, part, basics
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE