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 02: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.

CLIENT :


Code:

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

Try
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)
serverStream.Flush()

End If

Catch ex As Exception
End Try
Next

SERVER:


Code:

Dim serverSocket As New TcpListener(8888)
Dim requestCount As Integer
Dim clientSocket As TcpClient
serverSocket.Start()
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


clientSocket.Close()
serverSocket.Stop()

thank you.

passel 09-24-2013 08: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 01:07 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 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.