Table of Contents

Winsock

Winsock is a new concept to D++. Inspired by the community, it was added on version 3.2. Essentially, it works the same as the VB Winsock control. It uses an array of the control and dynamically sizes it. Therefore, the capabilties are limited to that of VB. It also only uses TCP currently, however it may support UDP connections in the future.

Declaraton

An important fact to note is that Winsock objects are global in D++, no matter which function you declare them in (they are not detected outside of functions). Therefore, if you were to create a Winsock in main(), you can use it in any other function. This is why I recommend declaring all Winsock controls in main(). They are easier to keep track of this way.

To declare a winsock object, you would use the following simple command. As you can see from it, you can declare more than one Winsock object per line.

winsock name1[, name2, name3, ...];

Properties/Methods

For the first time in D++, you can access the methods of an object. Because Winsock is so unique, it has it's own special format for accessing methods.

sock[name].method(args);

Now then, first of all, the above brackets [] are required (unlike my other examples, this does NOT mean that name is optional). Anyways, name is the name of your Winsock object, method is the method you wish to access, and args are any arguments (delimited by commas) that may be required for it, such as the variable to put the value in. The following methods are supported:

sock[name].connect(host, port);
sock[name].semd(data);
sock[name].listen(port);
sock[name].accept(requestID);
sock[name].getinfo(type, var);   ' type is "remoteIP" or "state"

The getinfo method is used for accessing winsock properties. The properties which are currently supported are “remoteIP” or “state”. The second argument, var, is the name of the variable that you wish to put the value of property into.

Events

The usage of winsock requires using D++ Format II code, or usage of functions. This is because the style is exactly like that of VB. When an event occures, D++ searches through the functions for the specific event to the function. If it finds it, the code is executed. The events that are supported are listed below.

name_connect()

Occurs when a a remote connection has been established.

name_close()

Occurs when the connection closes.

name_request(requestid)

Occurs when TCP connection has been requested.

name_incoming(data, bytesTotal)

Occurs when data arrives over the winsock connection.

name_error(description)

Occurs when a winsock error is detected.

One thing to keep in mind is the arguments. These arguments MUST be as typed below (not case sensitive). Otherwise you will get an error. In addition, make sure the name of your Winsock is used properly.

Back to D++ Documentation Index