September 23, 2018
Hot Topics:

Using Winsock

  • November 19, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

Let's briefly review the raw code for building a simple messaging program with the Winsock control. All of this code is based around what we have discovered already, with a few slight enhancements:

To Open a Connection

If Winsock1.State <> sckClosed Then Winsock1.Close

Winsock1.RemotePort = 1008Winsock1.RemoteHost = ""Winsock1.Connect

To Wait until Connected

Do Until Winsock1.State = sckConnectedDoEvents: DoEvents: DoEvents: DoEventsIf Winsock1.State = sckError ThenMsgBox "Problem connecting!"Exit SubEnd IfLoop

To Listen Out for Communication

Winsock1.LocalPort = 1008Winsock1.Listen

To Accept an Incoming Connection Request

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)    If Winsock1.State <> sckClosed Then Winsock1.Close    Winsock1.Accept requestIDEnd Sub

To Send Data

Winsock1.SendData ("Data Goes Here")

To Receive Incoming Data

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)        Dim strIncoming As StringWinsock1.GetData strIncomingx = strIncoming        End Sub

Page 4 of 9

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date