can any1 help me,what is wrong with these coding.values change from client are not shown at server's form.but if i put only 1 value,it show.why is that so??
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.Encoding
Public Class frmMain
Private Structure CAR_STATS
Dim IP As String
Dim Speed As String
Dim Fuel As String
Dim EngineTemperature As String
Dim Mileage As String
Dim InsideTemperature As String
Dim OutsideTemperature As String
Dim Humidity As String
Dim EngineOil As String
Dim RightFrontTyre As String
Dim LeftFrontTyre As String
Dim RightRearTyre As String
Dim LeftRearTyre As String
Dim Lamp As String
Dim SeatBelt As String
Dim OilFilter As String
Dim FuelFilter As String
Dim RadiatorWater As String
Dim BatteryElectrolyte As String
Dim Balancing As String
Dim Allignment As String
Dim PowerSteering As String
Dim AbsorberGas As String
Dim Break As String
Dim Coolant As String
Dim Refrigent As String
Dim WindowWasher As String
Dim TransmissionOil As String
Dim BreakFluid As String
End Structure
Private CarList(0) As CAR_STATS
Private Sub Listen_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Listen.DoWork
Dim server As New TcpListener(New IPEndPoint(IPAddress.Any, 10370))
While True
Try
server.Start()
Dim client As TcpClient = server.AcceptTcpClient
Dim str As NetworkStream = client.GetStream
Dim data As String = ""
Dim i As Integer = 0
Do While str.DataAvailable
i = str.ReadByte()
data &= Chr(i)
Loop
lstCars.Items.Clear()
UpdateList(ParseReply(client.Client.RemoteEndPoint.ToString, data))
Dim reply As String = ""
Dim remoteip As String = client.Client.RemoteEndPoint.ToString.Split(":")(0)
For i = 0 To CarList.Length - 1
reply &= CarList(i).IP & ";"
lstCars.Items.Add(CarList(i).IP)
Next
SendData(remoteip, reply)
client.Close()
Catch
End Try
End While
End Sub
Private Function ParseReply(ByVal IP As String, ByVal Reply As String) As CAR_STATS
Try
Dim Car As CAR_STATS
Car.IP = IP.Split(":")(0)
Dim Stats As String() = Reply.Split(";")
Car.Speed = Stats(0)
Car.Fuel = Stats(1)
Car.EngineTemperature = Stats(2)
Car.Mileage = Stats(3)
Car.InsideTemperature = Stats(4)
Car.OutsideTemperature = Stats(5)
Car.Humidity = Stats(6)
Car.EngineOil = Stats(7)
Car.RightFrontTyre = Stats(8)
Car.LeftFrontTyre = Stats(9)
Car.RightRearTyre = Stats(10)
Car.LeftRearTyre = Stats(11)
Car.Lamp = Stats(12)
Car.SeatBelt = Stats(13)
Car.OilFilter = Stats(14)
Car.FuelFilter = Stats(15)
Car.RadiatorWater = Stats(16)
Car.BatteryElectrolyte = Stats(17)
Car.Balancing = Stats(18)
Car.Allignment = Stats(19)
Car.PowerSteering = Stats(20)
Car.AbsorberGas = Stats(21)
Car.Break = Stats(22)
Car.Coolant = Stats(23)
Car.Refrigent = Stats(24)
Car.WindowWasher = Stats(25)
Car.TransmissionOil = Stats(26)
Car.BreakFluid = Stats(27)
Return Car
Catch
Return Nothing
End Try
End Function
Private Sub UpdateList(ByVal Car As CAR_STATS)
Label1.Text = CarList(0).Speed 'if only 1 list is chosen here,server's form show client's value
Label2.Text = CarList(1).Fuel
Label3.Text = CarList(2).EngineTemperature
Label4.Text = CarList(3).Mileage
Label5.Text = CarList(4).InsideTemperature
Label6.Text = CarList(5).OutsideTemperature
Label7.Text = CarList(6).Humidity
Label8.Text = CarList(7).EngineOil
Label9.Text = CarList(8).RightFrontTyre
Label10.Text = CarList(9).LeftFrontTyre
Label11.Text = CarList(10).RightRearTyre
Label12.Text = CarList(11).LeftRearTyre
Label13.Text = CarList(12).Lamp
Label14.Text = CarList(13).SeatBelt
Label15.Text = CarList(14).OilFilter
Label16.Text = CarList(15).FuelFilter
Label17.Text = CarList(16).RadiatorWater
Label18.Text = CarList(17).BatteryElectrolyte
Label19.Text = CarList(18).Balancing
Label20.Text = CarList(19).Allignment
Label21.Text = CarList(20).PowerSteering
Label22.Text = CarList(21).AbsorberGas
Label23.Text = CarList(22).Break
Label24.Text = CarList(23).Coolant
Label25.Text = CarList(24).Refrigent
Label26.Text = CarList(25).WindowWasher
Label27.Text = CarList(26).TransmissionOil
Label28.Text = CarList(27).BreakFluid
Dim i As Integer = 0
For i = 0 To CarList.Length - 1
If (CarList(i).IP Is Nothing) Or (CarList(i).IP = Car.IP) Then
CarList(i) = Car
Exit Sub
End If
Next
Array.Resize(CarList, CarList.Length + 1)
CarList(CarList.Length - 1) = Car
End Sub
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
frmMain.CheckForIllegalCrossThreadCalls = False
Listen.RunWorkerAsync()
End Sub
Private Sub SendData(ByVal IP As String, ByVal data As String)
Dim client As New TcpClient(IP, 10380)
Dim str As NetworkStream = client.GetStream
Dim buffer() As Byte = ASCII.GetBytes(data)
str.Write(buffer, 0, buffer.Length)
MyBase.Text = data
End Sub
End Class