Click here to Skip to main content
15,911,789 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Printing in 136 column wide mode Pin
Member 132035225-Aug-04 4:27
Member 132035225-Aug-04 4:27 
GeneralRe: Printing in 136 column wide mode Pin
Dave Kreskowiak25-Aug-04 5:13
mveDave Kreskowiak25-Aug-04 5:13 
GeneralRe: Printing in 136 column wide mode Pin
Member 132035228-Aug-04 2:12
Member 132035228-Aug-04 2:12 
GeneralRe: Printing in 136 column wide mode Pin
Anonymous25-Aug-04 7:43
Anonymous25-Aug-04 7:43 
GeneralVB.NET or VB from VS6 Pin
aslm24-Aug-04 12:27
aslm24-Aug-04 12:27 
GeneralRe: VB.NET or VB from VS6 Pin
Charlie Williams24-Aug-04 13:47
Charlie Williams24-Aug-04 13:47 
GeneralRe: VB.NET or VB from VS6 Pin
Dave Kreskowiak24-Aug-04 16:54
mveDave Kreskowiak24-Aug-04 16:54 
GeneralConvert TCP Class into thread Pin
jimmypearly24-Aug-04 11:30
jimmypearly24-Aug-04 11:30 
How do i convert the following into a fully multithreaded tcp server and remove the two addhandler(linerecieved,ondisconnected), i just know how
to remove the addhandler and make it into a separate thread.

any help would be appreciated.
thanks
jim

[UI form]
Option Strict On

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

Private myThread as thread
private mysocket as Tcplistener

Private Sub clsServer_load(...)
mythread = New threading.thread(addressof Dolisten)
mythread.start()
end sub
Pirvate dolisten()
dim localaddr = system.net.ipaddress
try
mysocket = new Tcplistener(localaddr,1234)
mysocket.start()
do
dim x as New clsClient(mysocket.AcceptTcpClient)
AddHandler x.Disconnected, AddressOf onDisconnected
AddHandler x.myReceived, AddressOf LineReceived
mcolClients.Add(x.ID, x)
Loop Until False
catch
end try
end sub

Public Sub LineReceived(ByVal sender As clsClient, ByVal strString As String)
'process recive data here

end sub

[clsClient.vb]

Option Strict On

Imports System.Net.Sockets
Imports System.Text

'client class to handle the new client connected to the server
Public Class clsClient
Public Event Disconnected(ByVal sender As clsClient)
Public Event LineReceived(ByVal sender As clsClient, ByVal Data As String)

Private mgID As Guid = Guid.NewGuid
Const BUFFER_SIZE As Integer = 512

Private mobjClient As TcpClient
Private marData(BUFFER_SIZE) As Byte
Private mobjText As New StringBuilder()

Public ReadOnly Property ID() As String
Get
Return mgID.ToString
End Get
End Property

Public Sub New(ByVal client As TcpClient)
mobjClient = client
mobjClient.GetStream.BeginRead(marData, 0, BUFFER_SIZE, AddressOf DoStreamReceive, Nothing)
End Sub

Private Sub DoStreamReceive(ByVal ar As IAsyncResult)

Dim intCount As Integer
Dim clientdata As String = Encoding.ASCII.GetString(marData)
Try
SyncLock mobjClient.GetStream
intCount = mobjClient.GetStream.EndRead(ar)
End SyncLock

If intCount < 1 Then
RaiseEvent Disconnected(Me)
Exit Sub
End If

RaiseEvent LineReceived(Me, clientdata)
SyncLock mobjClient.GetStream
mobjClient.GetStream.BeginRead(marData, 0, BUFFER_SIZE, AddressOf DoStreamReceive, Nothing)
End SyncLock

Catch ex As Exception
RaiseEvent Disconnected(Me)
End Try
End Sub

Public Sub Send(ByVal Data As String)
SyncLock mobjClient.GetStream
Dim w As New IO.StreamWriter(mobjClient.GetStream)
w.Write(Data)
w.Flush()
End SyncLock
End Sub

End Class




-just make it tough
GeneralRe: Convert TCP Class into thread Pin
Anonymous25-Aug-04 19:34
Anonymous25-Aug-04 19:34 
GeneralRe: Convert TCP Class into thread Pin
jimmypearly25-Aug-04 21:17
jimmypearly25-Aug-04 21:17 
GeneralRe: Convert TCP Class into thread Pin
Anonymous26-Aug-04 18:59
Anonymous26-Aug-04 18:59 
GeneralMacro app. - mouse click Pin
dadak24-Aug-04 9:02
dadak24-Aug-04 9:02 
GeneralRe: Macro app. - mouse click Pin
Purple Monk25-Aug-04 6:52
Purple Monk25-Aug-04 6:52 
GeneralRe: Macro app. - mouse click Pin
dadak25-Aug-04 7:33
dadak25-Aug-04 7:33 
GeneralRe: Macro app. - mouse click Pin
Dave Kreskowiak25-Aug-04 8:04
mveDave Kreskowiak25-Aug-04 8:04 
GeneralRe: Macro app. - mouse click Pin
dadak25-Aug-04 8:37
dadak25-Aug-04 8:37 
GeneralRe: Macro app. - mouse click Pin
Dave Kreskowiak25-Aug-04 10:23
mveDave Kreskowiak25-Aug-04 10:23 
GeneralRe: Macro app. - mouse click Pin
dadak25-Aug-04 11:47
dadak25-Aug-04 11:47 
GeneralRe: Macro app. - mouse click Pin
Purple Monk25-Aug-04 22:42
Purple Monk25-Aug-04 22:42 
GeneralRe: Macro app. - mouse click Pin
dadak26-Aug-04 5:58
dadak26-Aug-04 5:58 
GeneralRe: Macro app. - mouse click Pin
dadak26-Aug-04 9:07
dadak26-Aug-04 9:07 
GeneralRe: Macro app. - mouse click Pin
Purple Monk27-Aug-04 3:27
Purple Monk27-Aug-04 3:27 
Generalpopup menu on menuItem Pin
AstronusX24-Aug-04 9:00
AstronusX24-Aug-04 9:00 
GeneralRe: popup menu on menuItem Pin
Dave Kreskowiak24-Aug-04 10:24
mveDave Kreskowiak24-Aug-04 10:24 
GeneralRe: popup menu on menuItem Pin
AstronusX25-Aug-04 5:14
AstronusX25-Aug-04 5:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.