Hi guyz,
I'm trying to make a program that can send simple data back and forth between 2 computers over the the internet... At the moment i can only get it to send data over the LAN, i have setup my router to forward all incoming connections to a specific port to my computer but still no luck... anyone have any hints, here is the source code for the server and client...
SERVER CODE:-
TryListener = New TcpListener(IPAddress.Parse("127.0.0.1"), 22667) rchMessageBox.Text += "Starting IP Listener..." & vbCrLf
m_terminate =
False
Listener.Start()
Listener.BeginAcceptTcpClient(AddressOf ConnectionHandler, Nothing)
rchMessageBox.Text +=
"Server Awaiting Connections. Press Cancel to stop server." & vbCrLfCatch ex As Exception rchMessageBox.Text += "Could not start IP Listener" & vbCrLf
End Try
CLIENT CODE:-
Using client As New TcpClient Me.rchMessageBox.Text += "Attempting to connect to server on port 22666..." & vbCrLf
Tryclient.Connect(IPAddress.Parse("82.10.xxx.xxx"), 22667)
Catch ex As ExceptionMe.rchMessageBox.Text += "Error Connecting..." & vbCrLf
Exit Sub
End TryUsing writer As New BinaryWriter(client.GetStream)
writer.Write(
"ConNecT")Using reader As New BinaryReader(client.GetStream)
If reader.ReadString = "OK" ThenMe.rchMessageBox.Text += "Connection Established..." & vbCrLf writer.Write("ReqUesT")
If reader.ReadString = "FILE?" ThenMe.rchMessageBox.Text += "Connection Established..." & vbCrLf
writer.Write(txtFile.Text)
Dim filesize As Integer = Integer.Parse(reader.ReadString())
For i As Integer = 1 To filesizeMe.rchMessageBox.Text += Chr(client.GetStream.ReadByte)
NextMe.rchMessageBox.Text += vbCrLf & "Disconnecting..." & vbCrLf writer.Write("DisConNecT")
End If
ElseMe.rchMessageBox.Text += "Connection not complete" & vbCrLf
End If
End Using
End Using
End Using
I have left out all the threaded code because there is no problem with this, only the connecting...
This is in vb.net 2005
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).