• Здраво и добредојдовте на форумот на IT.mk.

    Доколку сеуште не сте дел од најголемата заедница на ИТ професионалци и ентузијасти во Македонија, можете бесплатно да се - процесот нема да ви одземе повеќе од 2-3 минути, а за полесна регистрација овозможивме и регистрирање со Facebook и Steam.

winsock on visual basic

  • Ја почнал/а темата
  • #1

petar.bt

Intern
12 август 2007
731
20
дали некој знае за "winsock on visual basic" нешто да објасни
 

Stane

Gaining Experience
4 октомври 2007
2,497
77
WinSock is a .DLL (Dynamic Link Library) and runs under Windows 3.x,
Windows for Workgroups, Windows NT, and Windows 95. The WINSOCK.DLL is
the interface to TCP/IP and, from there, on out to the Internet.
(TCP/IP stands for "Transmission Control Protocol / Internet
Protocol," the "language" that computers on the Internet use to
communicate with each other.)

The easiest way to show how it works is with a diagram:

WinSock-compliant Application (e.g., Netscape, WinVN)
|
WINSOCK.DLL
|
TCP/IP
|
Modem or Network card
|
Network and beyond

WINSOCK.DLL actually acts as a "layer" between your WinSock
applications and your TCP/IP stack. Your WinSock applications tell
WINSOCK.DLL what to do, WINSOCK.DLL translates these commands to your
TCP/IP stack, and your TCP/IP stack passes them on to the Internet!

But the most important thing for you to remember about WINSOCK.DLL is
that the WINSOCK.DLL you're using must match the version of TCP/IP
that you're running. Don't assume that because all WinSocks are called
WINSOCK.DLL that they're all the samethey're not. So, for example,
if I'm using Microsoft's TCP/IP, I can't use Trumpet Winsock.

Similarly, if I'm running on a SLIP connection, and I want to switch
from Chameleon Sampler's Winsock to Trumpet Winsock, I first need to
remove Chameleon's version of WINSOCK.DLL before installing the new
one.

If you end up with multiple versions of WINSOCK.DLL floating around
your hard disk, you're asking for trouble. Before you come screaming
at alt.winsock, take a couple of minutes to check your hard disk for
multiple WINSOCK.DLLs.
 

fuUuUzZzZy

On your way to fame
14 декември 2007
4,842
885
Ohrid
'Useful Winsock Functions:

'Winsock1.Listen 'This function makes your Winsock control listen on the LocalPort specified either with the function below or in the properties for this control.

'Winsock1.LocalPort 'This is the port where all incoming data arrives, including connection requests

'Winsock1.Connect [HostIP], [RemotePort] 'This will attempt to connect to the HostIP on the RemotePort of that computer, which should be what that computer is listening on. Both parameters are optional.

'Winsock1.Accept [requestID] 'This is how you accept a connection in the Winsock_ConnectionRequest Event. You must put Winsock1.Accept requestID.

'Winsock1.SendData [Data] 'This is what you use to send data with Winsock, you can send any time, but we recommend Strings with a special Function to Process it. The only 2 logical data types to send would be a Byte Array or a String.

'Winsock1.GetData [Data], [Type], [MaxLen] 'This is how you recieve all data from the Winsock control, Data = a variable, and Type = vbString,vbInteger etc. MaxLen is optional. This can only be used if data is sitting in the buffer, for instance using it in the Winsock_DataArrival event is a very practical use.

'Winsock1.RemoteHostIP [IPAddress] 'Use this to specify an IP address to connect to ahead of time.


___________________________________________________________________________


'Winsock Terminology

'Port - A port is a number used to divide up all the connections going on in your computer. For instance, this browser is running on the HTML port, some number like 250, and any data send to or from goes to port 250 of the receiving computer.
'Listen - To listen means to set aside a certain port number, and wait for a connection request on that port.
'IP Address - This number is used on the internet kind of like a social security number for your computer, computers send data to your IP Address and the data is only recieved by you.

_____________________________________________________________________________

'Philosophies (How it Works)

'Alright, so you understand all the events and methods right? Now lets move on to the actual programming parts. This is where we get into Client/Server programming, which means you have a Client, for instance, this browser is connected to my server, and is a client. My server, on the other hand is connected to you, was waiting for you to connect and did connect you so you could read this, now it sent you this text when you requested it.

'Server Functions:
'--->Listen for users and connect them to the application
'--->Get data from users and return requested data
'--->Hold all application logic and process to return data

'Client Functions:
'--->Connect to server application
'--->Request data, recieve returned business logic and read

'Ok we 'll start with the server, since it is the backbone of the whole data sending process, you can either have one set server, that you will be operating and maintaining, or have an application with both Server and Client built into it, so anyone can host a server. Games and chat programs use the latter, but it is not often used for anything else. For bigger programs, you'll want to connect with more that 1 user, which requires more than 1 Winsock Control. So create 2 winsock controls, one called sckConnect, and one called sckConnection and set its index to 0.

'Now you can either add in my MakeListen() function, or create your own, but in the end, you need to make your server listen (sckConnect.Listen) for connections. Then, in the sckConnect_ConnectionRequest Event, make it accept the port with a sckConnection(num) Winsock and start data flinging on those connections. I highly suggest using our ProcessData() function for sending complex data because it makes it very easy to send 3 strings and decode them.

'Now on to the Client. The client is where your users will be, so it needs to look sleek, and have no performance flaws. Keep the sending and winsock processes away from them, so they can't mess it up. First, you'll want to connect to the server, on whatever RemotePort its on, by using sckConnect.Connect "TheServerIPAddres"

'Next, you want to send data, so make some Command Buttons send data to the Server, which in turn should suck it up and process it, and return something to know that it was processed. This is how Winsock should work, send a piece, and recieve a conformation or the requested data as a conformation.

'All data you recieve will be in the Winsock_DataArrival Event, so you should always use this. Usually, its common to make a string, use Winsock.GetData TheString, vbString to grab the data from winsock, and process it therefore grabbing all data when it is recieved.

'You can debug your Winsock applications on one computer, simply run two instances of Visual Basic and run both of them. If you have a modem, use the IP "127.0.0.1" or if you have a network card, use your network IP. You should test it on other computers before releasing to the public though, because sometimes its different.
 

Wizardion

Intern
2 март 2008
111
1
Мислам дека новите пакети на Microsoft Visual Studio 2005/2008 немаат подршка на Winsock. Дали во новите пакети има некоја слична контрола на оваа?
 

Нови мислења

Последни Теми

Статистика

Теми
43,530
Мислења
822,725
Членови
28,053
Најнов член
ro0tkid
На врв Дно