September 3, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

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 = "127.0.0.1"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.

 

 


Sitemap | Contact Us

Rocket Fuel