I am re-creating a program that was made in vb6. The vb6 program used winsockets for networking. It could host up to 70 clients and there would be constant communication back and fourth. I have just recently switched to using .NET... (Huge Change) more specifically Visual Studio 2010 express (for now). Basically, in effort to re-create this type of data communication I have run into a road block.
Here is my current code for reading/accepting clients... it is not yet done. It is quite messy and has unnecessary code which I just havnt removed yet.
Anyways, on to my question. In this code it reads data from the Clients(i).GetStream then it runs the handle data sub.
When I run this code. After it reads the stream it basically resets the socket. I can no longer send data and most everything I do with it returns an instance error.
Any suggestions?
Thanks in Advance!
VB.NET:
Public Sub DoListen()
Dim i As Long
Dim publicip As String
Dim buffer As ByteBuffer
buffer = New ByteBuffer
For i = 0 To MAX_PLAYERS
Clients(i) = New Net.Sockets.TcpClient
Next
ReDim ClientIps(0 To MAX_PLAYERS)
restart:
Do
For i = 0 To MAX_PLAYERS
If Clients(i).Connected = False Then
If listener.Pending = True Then
Clients(i) = listener.AcceptTcpClient()
Dim ipend As Net.IPEndPoint = Clients(i).Client.RemoteEndPoint
If Not ipend Is Nothing Then
publicip = ipend.Address.ToString
Else
publicip = ""
End If
ClientIps(i) = publicip
On Error GoTo handleerror
AddTextMsg = ("Received connection from " & ClientIps(i))
If Clients(i).GetStream.DataAvailable = True Then
' Read the stream into a byte array
Dim bytes(Clients(i).ReceiveBufferSize) As Byte
bytes = Nothing
ReDim bytes(Clients(i).ReceiveBufferSize)
Clients(i).GetStream.Read(bytes, 0, CInt(Clients(i).ReceiveBufferSize))
buffer.WriteBytes(bytes)
Call HandleData(i, buffer.ReadLong, bytes)
buffer = Nothing
End If
End If
Else
If Clients(i).GetStream.DataAvailable = True Then
buffer = New ByteBuffer
' Read the stream into a byte array
Dim bytes(Clients(i).ReceiveBufferSize) As Byte
bytes = Nothing
ReDim bytes(Clients(i).ReceiveBufferSize)
Clients(i).GetStream.Read(bytes, 0, CInt(Clients(i).ReceiveBufferSize))
buffer.WriteBytes(bytes)
Call HandleData(i, buffer.ReadLong, bytes)
buffer = Nothing
End If
End If
Next i
Loop
Here is my current code for reading/accepting clients... it is not yet done. It is quite messy and has unnecessary code which I just havnt removed yet.
Anyways, on to my question. In this code it reads data from the Clients(i).GetStream then it runs the handle data sub.
When I run this code. After it reads the stream it basically resets the socket. I can no longer send data and most everything I do with it returns an instance error.
Any suggestions?
Thanks in Advance!