Quote
' Sender's end.
Public Structure Chat
Dim fromPlayerID As Integer
Dim toPlayerID As Integer
Dim Message As String
End Structure
Sub Main
Dim C as Chat
C.Message = “Test”
SendData(“CHAT”, C)
End Sub
Public Overloads Sub SendData(ByVal pHeader As String, ByVal pData As Object)
Dim packet As New NetworkPacket
Dim data(30) As Byte
Dim st As Stream = New MemoryStream(data, True)
Dim sw As New StreamWriter(st)
sw.WriteLine(pHeader)
sw.WriteLine(pData)
sw.Close()
packet.Write(data)
m_Client.Send(packet, 0, SendFlags.Sync Or SendFlags.NoLoopback) ' Outgoing data
End Sub 'SendData
' Reciever's end.
Public Sub ReceiveHandler(ByVal sender As Object, ByVal args As ReceiveEventArgs)
Dim head As String
Dim str As String
Dim packet As NetworkPacket
packet = args.Message.ReceiveData
Dim buf As Byte()
ReDim buf(packet.Length)
buf = CType(packet.Read(GetType(Byte), packet.Length), Byte())
Dim st As Stream = New MemoryStream(buf)
Dim sr As New StreamReader(st)
head = sr.ReadLine()
'***Problem*** At this point, Head can read the message "CHAT" but how do I read the structure C ?
Select Case head
Case "CHAT"
'***Problem*** Here, how to read data from structure C ?
End Select
sr.Close()
End Sub 'ReceiveHandler
Public Structure Chat
Dim fromPlayerID As Integer
Dim toPlayerID As Integer
Dim Message As String
End Structure
Sub Main
Dim C as Chat
C.Message = “Test”
SendData(“CHAT”, C)
End Sub
Public Overloads Sub SendData(ByVal pHeader As String, ByVal pData As Object)
Dim packet As New NetworkPacket
Dim data(30) As Byte
Dim st As Stream = New MemoryStream(data, True)
Dim sw As New StreamWriter(st)
sw.WriteLine(pHeader)
sw.WriteLine(pData)
sw.Close()
packet.Write(data)
m_Client.Send(packet, 0, SendFlags.Sync Or SendFlags.NoLoopback) ' Outgoing data
End Sub 'SendData
' Reciever's end.
Public Sub ReceiveHandler(ByVal sender As Object, ByVal args As ReceiveEventArgs)
Dim head As String
Dim str As String
Dim packet As NetworkPacket
packet = args.Message.ReceiveData
Dim buf As Byte()
ReDim buf(packet.Length)
buf = CType(packet.Read(GetType(Byte), packet.Length), Byte())
Dim st As Stream = New MemoryStream(buf)
Dim sr As New StreamReader(st)
head = sr.ReadLine()
'***Problem*** At this point, Head can read the message "CHAT" but how do I read the structure C ?
Select Case head
Case "CHAT"
'***Problem*** Here, how to read data from structure C ?
End Select
sr.Close()
End Sub 'ReceiveHandler
Thank you.
/bow











