Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Winsock
Message
De
22/04/1999 13:27:26
 
 
À
21/04/1999 06:13:15
Information générale
Forum:
Visual Basic
Catégorie:
Autre
Titre:
Divers
Thread ID:
00210447
Message ID:
00211154
Vues:
28
The Winsock control let you connect to a remote machine and exchange data using DCP or TCP.

In order to connect you must supply a Protocol type.
(For the example I assume that you have called the control Winsock1)
Winsock1.Protocol = sckTCPProtocol (or sckUDPProtocol)

You must decide which computer will be the server and which is the client
Sub Form1_Init
'(Server Side)
Winsock1.LocalPort
Winsock1.Listen
End Sub
-----------------
Sub Form1_Init
'(Client side)
'To connect to a remote computer you must now its IP or its name
Winsock1.RemoteHost = "Remote Computer Name"
Winsock1.RemotePort = 1001
End Sub

Private Sub Command1_Click
'Command button to connect to the server
Winsock1.Connect
End Sub

The Winsock control has a method called Connection_Request where you normally have to accept the connection requested:

Private Sub Winsock1_ConnectionRequest(ByVal requestID as Long)
'Server side
'Here you can put code to check that there are not other opened connection 'and, eventually, close it.
Winsock1.Accept requestID
End Sub

Now that the connection is established you can easily send data with that command:

Winsock1.SendData datavariable

And retrieve that with:

Private Sub Winsock1_DataArrival(ByVal bytesTotal as Long)
Dim strData as String 'or other type

Winsock1.GetData strData
End Sub

Of course, the last method is fired when data is retrieved by the other machine.
I think that this is information can get you confused, but if you try to create a program of 2 computer that try to communicate each other(maybe sending some text) with this code will help you better.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform