Hello,
I just got done creating a very primitive server/client chat program using winsock. I transfered the program to another computer, but when I tried to connect to it I got the error "Address is not available from the local machine". The problem shouldn't be a firewall or anything, since I disabled it on both computers, and I even messed around with my router a bit so it wouldn't block anything.
Here's the Client application:
And the Server application:Code:Option Explicit Private Sub btnConnect_Click() On Error GoTo connectError sock1_Close sock1.RemoteHost = txtIP.Text sock1.Connect Exit Sub connectError: txtLogAdd ("***Error: " & Err.Description) End Sub Private Sub btnDisconnect_Click() sock1_Close End Sub Private Sub btnExit_Click() txtLogAdd ("***Exiting") sock1_Close End End Sub Private Sub btnSend_Click() On Error GoTo sendError sock1.SendData txtChat.Text txtLogAdd ("Client: " & txtChat.Text) Exit Sub sendError: txtLogAdd ("***Error: " & Err.Description) sock1_Close End Sub Private Sub sock1_Connect() txtLogAdd ("Connected to " & sock1.RemoteHostIP) End Sub Private Sub txtLogAdd(strChat As String) Dim minuteAdd As String Dim secondAdd As String If Second(Now) < 10 Then secondAdd = "0" Else secondAdd = "" End If If Minute(Now) < 10 Then minuteAdd = "0" Else minuteAdd = "" End If txtLog.Text = txtLog.Text & "[" & Hour(Now) & ":" & minuteAdd & Minute(Now) & ":" & secondAdd & Second(Now) & "]" & strChat & vbCrLf End Sub Private Sub sock1_DataArrival(ByVal bytesTotal As Long) Dim strReceived As String sock1.GetData strReceived, vbString txtLogAdd ("Server: " & strReceived) End Sub Private Sub sock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) txtLogAdd ("***Error: " & Description) sock1_Close End Sub Private Sub sock1_Close() sock1.Close txtLogAdd ("***Connection Closed") End Sub
I would greatly appreciate any help.Code:Option Explicit Private Sub btnClose_Click() txtLogAdd ("***Closing Port " & sock1.LocalPort) sock1_Close End Sub Private Sub btnExit_Click() txtLogAdd ("***Exiting") sock1.SendData "Server is terminating" sock1_Close End End Sub Private Sub btnListen_Click() On Error GoTo listenError sock1_Close sock1.LocalPort = txtPort.Text sock1.Listen Exit Sub listenError: txtLogAdd ("***Error: " & Err.Description) End Sub Private Sub btnSend_Click() On Error GoTo sendError sock1.SendData txtChat.Text txtLogAdd ("Server: " & txtChat.Text) Exit Sub sendError: txtLogAdd ("***Error: " & Err.Description) sock1_Close End Sub Private Sub txtLogAdd(strChat As String) Dim minuteAdd As String Dim secondAdd As String If Second(Now) < 10 Then secondAdd = "0" Else secondAdd = "" End If If Minute(Now) < 10 Then minuteAdd = "0" Else minuteAdd = "" End If txtLog.Text = txtLog.Text & "[" & Hour(Now) & ":" & minuteAdd & Minute(Now) & ":" & secondAdd & Second(Now) & "]" & strChat & vbCrLf End Sub Private Sub sock1_ConnectionRequest(ByVal requestID As Long) If sock1.State <> sckClosed Then sock1.Accept requestID txtLogAdd ("***Client Connected") txtLogAdd ("***IP: " & sock1.RemoteHostIP) End If End Sub Private Sub sock1_DataArrival(ByVal bytesTotal As Long) Dim strReceived As String sock1.GetData strReceived, vbString txtLogAdd ("Client: " & strReceived) End Sub Private Sub sock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) txtLogAdd ("***Error: " & Description) sock1_Close End Sub Private Sub sock1_Close() sock1.Close txtLogAdd ("***Connection Closed") End Sub


Reply With Quote