Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Communications (http://www.xtremevbtalk.com/-net-communications/)
-   -   Socket Multiple Connection VB.NET (http://www.xtremevbtalk.com/-net-communications/326451-socket-multiple-connection-vb-net.html)

eawedat 09-24-2013 01:10 AM

Socket Multiple Connection VB.NET
hey all,

I wish to send message to multiple computers (LAN network).

each computer in lab is running the server except one computer which is the client.

Problem : once message has been sent to first computer , the client stops to send to other computers.



Dim ip As String
Dim i As Integer
Dim serverStream As NetworkStream
Dim outStream As Byte()

Dim counter As Integer = 0
For i = 0 To 100

ip = txtRange.Text & i

clientSocket.Connect(ip, 8888)

If clientSocket.Connected = True Then

serverStream = clientSocket.GetStream()
outStream = System.Text.Encoding.ASCII.GetBytes("Message from the client$")
serverStream.Write(outStream, 0, outStream.Length)

End If

Catch ex As Exception
End Try



Dim serverSocket As New TcpListener(8888)
Dim requestCount As Integer
Dim clientSocket As TcpClient
clientSocket = serverSocket.AcceptTcpClient()

While (true)

Dim networkStream As NetworkStream = clientSocket.GetStream()
Dim bytesFrom(10024) As Byte
networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
Dim dataFromClient As String = System.Text.Encoding.ASCII.GetString(bytesFrom)
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
MessageBox.Show("Data from client -  " + dataFromClient)
End While


thank you.

passel 09-24-2013 07:46 AM

Do you have to use TCP?
It would seem using UDP and doing a broadcast would be more efficient.
In any case, I believe you have to disconnect your socket from the current machine before you can connect it to the next machine.
If you need to keep multiple connections open, then you need multiple sockets on your client, one for each server, to maintain the connection to a given machine.

All times are GMT -6. The time now is 10:00 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.