Jump to content
xisto Community
Sign in to follow this  
ghostrider

An Indepth Look At The Winsock Control (part Ii) Part II - Events of the Winsock Control

Recommended Posts

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 event and our code will handle it from there. There are 7 events, and they are named, Close, Connect, ConnectionRequest, DataArrival, Error, SendComplete, and SendProgress.

The Close Event:
The Close event is fired whenever a connection is closed. This only happens when you are using the TCP protocol. I usually never use this event when I write code for the Winsock control. It has no arguments

The Connect Event:
The Connect event is fired whenever a connection is made. This also is only fired when you are using the TCP protocol. I also almost never use this event.

The ConnectionRequest Event:
The ConnectionRequest event is fired when a computer is listening for a connection and a computer would like to connect to it. It has one argument, called requestID. Each connection made to a control has its own unique requestID. To connect to a computer you use the Accept function of the Winsock control. The accept function finalizes the connection and allows both computers to start sending data. This event is only fired when you are using the TCP protocol.

The DataArrival Event:
Unlike the last 3 events, this event event can be fired using both TCP and UDP protocols. It has one argument, called bytesTotal. This arugment contains how many bytes were received. You can get the data using the function GetData or PeekData.

The Error Event:
The Error event is fired whenever an error occurs. It has a lot of arguments, 7 to be exact, but we are only going to use the first two arguments, Number which contains the error number, and Description, which describes the error. This event is fired regardless of the protcol you are using.

The SendComplete Event:
This event is fired when the data is completed sending. I never really use it. It has no arguments and can be used when you are using TCP and UDP. If I choose to include file sharing in our chat program, then it will be used.

The SendProgess Event:
This event is fired whenever data is being sent which is pretty much all the time. It has two arugments, bytesSent and bytesRemaining, which are both self explanatory. I almost never use this, but like with the SendComplete event, if we share files it will be used. You can calculate the percent of the file that has been sent using this equation. percent = bytesSent / (bytesSent + bytesRemaining) * 100.

How to Add the Winsock Control to your Toolbar:
Here are the steps for adding the Winsock control:
1. On the menu at the way top, click Project.
2. Click Components.
3. Find Microsoft Winsock Control 6.0 (SP5)
4. Click the check box next to it.
5. Click OK.

The Winsock control should now be on your toolbar and be ready for use. Part III is coming soon, and we will start writing some actual code then.

Edited by ghostrider (see edit history)

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.