Q: How do I retrieve a list of Local IP Address?

A:
Code:
Imports System.Net 
 
	Public Function GetLIPAdresses() As ArrayList 
		Dim NetInterfaces() As NetworkInformation.NetworkInterface = NetworkInformation.NetworkInterface.GetAllNetworkInterfaces 
		Dim IPList As New ArrayList 
		Try 
		 For Each NetInterface As NetworkInformation.NetworkInterface In NetInterfaces 
				Dim infosDns As NetworkInformation.UnicastIPAddressInformationCollection = NetInterface.GetIPProperties.UnicastAddresses 
				For Each address As NetworkInformation.UnicastIPAddressInformation In infosDns 
					IPList.Add(address.Address.ToString) 
				Next 
			Next 
		Catch ex As Exception 
			MessageBox.Show("Error: " & ex.Message) 
		End Try 
	 Return IPList 
	End Function
'Code is thanks to aniskhan.

Q: How do I init a TCP port for linking (Listen or Client)

A:
Code:
Imports System.Net 
Imports System.Text 
 
	Public Enum TCP_State 
		Listen 
		Conect 
		Client 
	End Enum 
	Private TCP_Listen As Sockets.TcpListener 
	Private TCP_Client As Sockets.TcpClient 
	Private Con_Method As TCP_State 
	Public Event Socket_Error(ByVal Err As Exception) 
 
	Public Function Init(ByVal Method As TCP_State, ByVal Port As Integer) As Boolean 
		Try 
			Con_Method = Method 
			Select Case Con_Method 
				Case TCP_State.Client 
					TCP_Client = New Sockets.TcpClient 
				Case TCP_State.Listen 
					TCP_Listen = New Sockets.TcpListener(L_IP, Port) 
					TCP_Listen.Start() 
				Case Else 
					Exit Function 
			End Select 
			C_Timer.Enabled = True 
			Init = True 
		Catch ex As Exception 
			Init = False 
			RaiseEvent Socket_Error(ex) 
		End Try 
	End Function
Q: How do I connect to a listening TCP port (Client)

A:
Code:
	Public Function Connect(ByVal HostAddress As IPAddress, ByVal Port As Integer) As Boolean 
		Select Case Con_Method 
			Case TCP_State.Client 
				Try 
					TCP_Client.Connect(HostAddress, Port) 
					Return True 
				Catch ex As Exception 
					RaiseEvent Socket_Error(ex) 
					Return False 
				End Try 
			Case Else 
				Return False 
		End Select 
	End Function


Q: How do I accept a connection request to a listening TCP port


A: Because the Net class does not raise events, we need to use a timer to check if a connection request is pending, there after we can raise our own event.
Code:
	Private WithEvents C_Timer As System.Windows.Forms.Timer
Code:
	Public Event Connection_Request(ByVal Remote_IP As EndPoint) 
	Private Con_Proc As Boolean 
	Private Sub C_Timer_Elapsed(ByVal sender As Object, ByVal e As System.EventArgs) Handles C_Timer.Tick 
		Select Case Con_Method 
			Case TCP_State.Listen 
			 If TCP_Listen.Pending Then 
					TCP_Client = TCP_Listen.AcceptTcpClient 
					RaiseEvent Connection_Request(TCP_Client.Client.RemoteEndPoint) 
					Con_Method = TCP_State.Conect 
					Con_Proc = True 
					' Close listening port... We've got our conection 
					TCP_Listen.Stop() 
					TCP_Listen = Nothing 
				End If 
		End Select 
	End Sub


Q: How do I check the connection status during a TCP connection


A: The following code snip runs in the same timer event as above.
Code:
	Public Event Connection_Complete(ByVal Remote_IP As EndPoint)
Code:
	Public Event Connection_Error()
	Private Sub C_Timer_Elapsed(ByVal sender As Object, ByVal e As System.EventArgs) Handles C_Timer.Tick
		Select Case Con_Method
			Case TCP_State.Client, TCP_State.Conect
				If Con_Proc Then
					If TCP_Client.Available > 0 Then
						Try
							ReDim RecievedBytes(TCP_Client.Available - 1)
							TCP_Client.GetStream.Read(RecievedBytes, 0, TCP_Client.Available)
							Tot_Array = UBound(B_Data) + 1
							ReDim Preserve B_Data(Tot_Array)
							ReDim Preserve B_Sender(Tot_Array)
							ReDim Preserve Raw_Data(Tot_Array)
							B_Data(Tot_Array) = Encoding.ASCII.GetString(RecievedBytes)
							B_Sender(Tot_Array) = RemoteIpEndPoint.Address
							Raw_Data(Tot_Array).Data = RecievedBytes
							I_Timer.Enabled = True
					 Catch ex As Exception
							RaiseEvent Socket_Error(ex)
						End Try
					End If
					If Not TCP_Client.Connected Then
						RaiseEvent Connection_Error()
					End If
				Else
					If TCP_Client.Connected 
						RaiseEvent Connection_Complete(TCP_Client.Client.RemoteEndPoint) 
						Con_Proc = True 
					End If 
			 End If 
		End Select 
	End Sub