|
-
Mar 21st, 2002, 02:00 PM
#1
Thread Starter
Junior Member
Winsock tutorial
I was folowing the winsock tutorial and when i finished it I coppied the code and launched another instance of VB, then I changed the "Winsock1.LocalPort" to 202 instead of 201 like it said in the tutorial. It does not work, and i dont know why.
here is my code.
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdSend_Click()
If Winsock1.State <> sckClosed Then
Winsock1.Close
Else
If MsgBox("You are not conected do you wish to connect" _
, vbYesNo + vbQuestion) = vbYes Then
'Connect to machene
Winsock1.RemoteHost = "127.0.0.1" 'txtAddress.Text
Winsock1.RemotePort = 202
Winsock1.Connect
'wait for connection
Do Until Winsock1.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents: DoEvents
If Winsock1.State = sckError Then
MsgBox "Problem Connecting"
Exit Sub
End If
Loop
'send data
Winsock1.SendData ("txtMessage.text")
Else
Call MsgBox("ok -not connected")
End If
End If
End Sub
Private Sub Form_Load()
On Error GoTo PortErr
Winsock1.LocalPort = 201
Winsock1.Listen
Me.Caption = "NCS - Network Chat Software " & "(" & Winsock1.LocalIP & ")"
Exit Sub
PortErr:
MsgBox "Another Program is using port 201"
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'Display incoming data
Dim strIncoming As String
Winsock1.GetData strIncoming
txtIncoming = strIncoming
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|