Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net
- Imports System.Net.Sockets
- Imports System.IO
- Public Class mainForm
- Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Dim blah As backgroundServer
- initServer()
- blah = New backgroundServer
- blah.bgServerInstance.RunWorkerAsync()
- ' updateServerLabel("called from main") <--works
- End Sub
- Public Sub updateServerLabel(ByVal strMessage As String)
- lblServerInfo.Text = strMessage
- End Sub
- End Class
- Imports System.Net
- Imports System.Net.Sockets
- Imports System.IO
- Module bgServer
- Public strLocalIP As String
- Public strHostName As String
- Public intPortNumber As Int32
- Public Sub initServer()
- strHostName = System.Net.Dns.GetHostName()
- strLocalIP = System.Net.Dns.GetHostEntry(strHostName).AddressList(0).ToString
- intPortNumber = 1052
- ' mainForm.updateServerLabel("called from init") <--works
- End Sub
- Public Class backgroundServer
- Public WithEvents bgServerInstance As New System.ComponentModel.BackgroundWorker
- Private Sub bgServerInstance_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgServerInstance.DoWork
- Dim server As TcpListener = Nothing
- Dim client As TcpClient = Nothing
- Dim stream As NetworkStream = Nothing
- Dim port As Int32 = 8888
- Dim localAddr As IPAddress = IPAddress.Parse(strLocalIP)
- Dim data As String = Nothing
- Dim i As Int32
- Dim bytes(1024) As Byte
- Dim retMsg As Byte() = System.Text.Encoding.ASCII.GetBytes("Default Reply")
- mainForm.updateServerLabel("called from bg") '<-- does not work
- server = New TcpListener(localAddr, port)
- server.Start()
- While (True)
- Try
- client = server.AcceptTcpClient()
- MsgBox("client accepted!") '<--works
- client.Close()
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End While
- End Sub
- End Class
- End Module
Add Comment
Please, Sign In to add comment