Hello forum.
Im working on threaded tcp server and i faced very strange problem and i can't find anything from google what can help me. Basicly im calling sub Send from module, it should work. But i get exception error and when i move my cursor to mS it says = Nothing . Where my object did go?
Here is code
Im working on threaded tcp server and i faced very strange problem and i can't find anything from google what can help me. Basicly im calling sub Send from module, it should work. But i get exception error and when i move my cursor to mS it says = Nothing . Where my object did go?
Here is code
VB.NET:
Public Class NetSession Private Hash As String = Guid.NewGuid.ToString()
Private PlayerList As New ArrayList()
Public PlayerPassword As New ArrayList()
Public PlayerUsername As New ArrayList()
Private mC As System.Net.Sockets.TcpClient
Public mS As System.Net.Sockets.NetworkStream
Private mThreadCounter As Integer
Private mIndex As String
Public Sub New(ByVal C As System.Net.Sockets.TcpClient,
ByVal ThreadCounter As Integer)
Me.mC = C
Me.mThreadCounter = ThreadCounter
Me.mIndex = ""
End Sub
Public Sub New()
' TODO: Complete member initialization
End Sub
Public Sub SessionLoop()
Me.mS = Me.mC.GetStream()
Me.mC.LingerState.Enabled = False
Me.Send("0x00" & Hash)
While Me.mC.Connected
If Me.mS.DataAvailable Then
Dim GotData As New System.Text.StringBuilder()
While Me.mS.DataAvailable
Dim bytes(Me.mC.ReceiveBufferSize - 1) As Byte
Dim Len = Me.mS.Read(bytes, 0, Me.mC.ReceiveBufferSize)
If Len > 0 Then
GotData.Append(System.Text.Encoding.UTF8.GetString(bytes, 0, Len))
End If
End While
Dim D = GotData.ToString().Trim()
If Not D = "" Then
If Not Me.Handle(D) Then
Exit While
End If
End If
End If
End While
Me.mS.Close()
Me.mS.Dispose()
Me.mC.Close()
Console.WriteLine("Thread " & Me.mThreadCounter.ToString() & " is closing.")
End Sub
Sub Send(ByVal T As String)
Dim Bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(T & ControlChars.CrLf)
Me.mS.Write(Bytes, 0, Bytes.Count)
Me.mS.Flush()
End Sub
Public Function Handle(ByVal D As String) As Boolean
Console.WriteLine("Thread " & Me.mThreadCounter.ToString() & ": " & D)
If D.Substring(0, 4) = "FINN" Then
Return False
Else
Select Case D.Substring(0, 4)
Case "0x00" : Call ModPackets.Login0x00(D.Substring(4, D.Length - 4))
Case "0x01" : Call ModPackets.Login0x01(D.Substring(4, D.Length - 4))
Case Else
Console.WriteLine("Unparsed packet " + D.Substring(0, 4) + " Data: " + D.Substring(4, D.Length - 4))
End Select
Return True
End If
End Function
End Class