0 Replies - 972 Views - Last Post: 11 July 2009 - 09:55 AM Rate Topic: -----

#1 VBasic Brett  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-July 09

P2P VB project help required

Post icon  Posted 11 July 2009 - 09:55 AM

Hello, I am very new to visual Basic and this is only my second project. I saw the below code on this site and wanted to use it to see how it works.

The code worked and it displayed a message successfully.

However, I asked a friend if they would give my their IP address so I could see if it worked to send across the internet (As I believe this code is meant to do). When I added their IP address and ran the program the error message I got was:

"Not listening. You must call the Start() method before calling this method." This error was againt the line of code that says.

If Listener.Pending = True Then

Any ideas regarding the cause, i tried a few things to no evail. Thanks

Imports System.Net.Sockets
Imports System.Threading
Imports System.IO

Public Class Form1
	Dim Listener As New TcpListener(65535)
	Dim Client As New TcpClient
	Dim Message As String = ""

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Dim ListThread As New Thread(New ThreadStart(AddressOf Listening)) 'Creates the thread
		ListThread.Start() 'Starts the thread
	End Sub
	Private Sub Listening()
	End Sub
	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		If Listener.Pending = True Then
			Message = ""
			Client = Listener.AcceptTcpClient()

			Dim Reader As New StreamReader(Client.GetStream())
			While Reader.Peek > -1
				Message = Message + Convert.ToChar(Reader.Read()).ToString
			End While

			MsgBox(Message, MsgBoxStyle.OkOnly)
		End If
	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Client = New TcpClient("", 65535)

		Dim Writer As New StreamWriter(Client.GetStream())
	End Sub
	Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
	End Sub
End Class

Is This A Good Question/Topic? 0
  • +

Page 1 of 1