Using Winsock, Page 4
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.CloseWinsock1.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
0 Comments (click to add your comment)
Networking Solutions
