Alright well I had a question before when i was a noob and posted here and got such a great response this has become my main vb site. Anyways I have a comp that cant run msn due to it being a piece of crap :P so I decided to make a chat client with winsock and direct ip's.
Basically what it does is gives you the option of connecting to the ip or listening for incomming connections from an ip. The problem is i cant get winsock to send a connection request to the ip. I made it go through port 2 since ive never encountered anything using port 2 and its a default port so I figured I would be avoiding an error there. So I used a port scanner and scanned to see if port 2 was open and not realising port scanners send connection requests to the specified ports. Once it scanned port 2 I got a message on my main form saying "my ip" has requested a connection do you accept? (I made a msgbox under Winsock1_Connec tion request so that was supposed to happen) So I guess nothing is wrong with that part is just the sending of the connection request that wont work.
Screenshot of the forms so you can see what im talking about:

Also theyre on two different forms the Menu is the main form and once your connected then Menu hides and Chat comes up.
Heres my code so you can understand what im doing and where i went wrong
Also This is my chat part code (Doesnt matter as much as the connecting part.)
Any help on how to make them connect would be appreciated. :P
Basically what it does is gives you the option of connecting to the ip or listening for incomming connections from an ip. The problem is i cant get winsock to send a connection request to the ip. I made it go through port 2 since ive never encountered anything using port 2 and its a default port so I figured I would be avoiding an error there. So I used a port scanner and scanned to see if port 2 was open and not realising port scanners send connection requests to the specified ports. Once it scanned port 2 I got a message on my main form saying "my ip" has requested a connection do you accept? (I made a msgbox under Winsock1_Connec tion request so that was supposed to happen) So I guess nothing is wrong with that part is just the sending of the connection request that wont work.
Screenshot of the forms so you can see what im talking about:

Also theyre on two different forms the Menu is the main form and once your connected then Menu hides and Chat comes up.
Heres my code so you can understand what im doing and where i went wrong
Code:
Private Sub cmdConnect_Click()
On Error Resume Next
If txtIp.Text = W1.LocalIP Then
MsgBox "You cannot connect to yourself."
txtIp.SetFocus
txtIp.Text = ""
End If
W1.RemoteHost = txtIp.Text 'tells the winsock which IP we should connect to.
W1.RemotePort = 2 'tells the winsock which port we should connect to.
W1.Connect
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdListen_Click()
W1.RemoteHostIP = txtIp.Text
W1.LocalPort = 2
W1.Listen
End Sub
Private Sub Form_Load()
Label3.Caption = " Your IP: " & W1.LocalIP
End Sub
Private Sub label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End Sub
Private Sub lblBackground_Click()
End Sub
Private Sub W1_Connect() 'When someone Connects to your server
MsgBox W1.RemoteHostIP & " Connected!" 'Show an MSGbox with the remoteIP
Me.Hide
frmChat.Show
End Sub
Private Sub W1_ConnectionRequest(ByVal requestID As Long)
Dim Message As String
Message = MsgBox(W1.RemoteHostIP & " Has requested a connection with you." & vbCrLf & "Do you accept?", vbYesNo + vbInformation, "Connection Request")
If Message = vbYes Then
Me.Hide
frmChat.Show
End If
End Sub
Code:
Private strDisplayName As String
Private Sub cmdClose_Click()
Unload Me
frmMenu.Show
End Sub
Private Sub cmdExit_Click()
Unload Me
frmMenu.Show
End Sub
Private Sub cmdSend_Click()
txtChat.AddItem strDisplayName & ": " & txtMessage.Text
txtMessage.Text = ""
End Sub
Private Sub Form_Load()
strDisplayName = InputBox("Please enter your display name", "Display name")
txtChat.Clear
txtChat.AddItem "Welcome to HaggardSmurf's direct IP chat client. "
txtChat.AddItem "Your connected with: " & W1.RemoteHostIP
Label1.Caption = " Direct Chat"
End Sub
Private Sub label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End Sub
Private Sub Timer1_Timer()
If txtChat.AddItem Then
frmChat.SetFocus
txtMessage.SetFocus
End If
End Sub
Private Sub txtMessage_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyReturn) Then
cmdSend_Click
End If
End Sub