dcsimg
Results 1 to 11 of 11

Thread: Socket Multiple Connection VB.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    13

    Question 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.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Socket Multiple Connection VB.NET

    each computer in lab is running the server except one computer which is the client.
    Say what now? That makes no sense at all. Sending a message from one server to 7 clients perfectly normal. Sending a message from one client to 7 clones of a single server would appear to be bordering on insane!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    13

    Re: Socket Multiple Connection VB.NET

    dunfiddlin with all respect , I do not think that there is different because once TCP/IP connection has been made , it does not matter.
    connection is connection , it is like someone calls you , or you call someone , the goal is that you speak with each others.

    ALSO , I do not think there is clone at all that's because each server has diffrenet ip address.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Socket Multiple Connection VB.NET

    each server has diffrenet ip address.
    And therefore needs its own connection which is precisely why it's bonkers. In order to communicate it is necessary to open 7 connections from each client. Now it helps that you only have one (although it's hard to see what the poor thing has done to get the subservient role!) but it's still completely over the top. The whole point of the server client relationship is that each client machine is able to make the same single connection to the server which co-ordinates all traffic. Your arrangement is essentially peer-to-peer and not server client at all but it's not even a good example of that.

    You say that a connection is a connection but there's a complete absence of communication in your set up. The servers have no communication with each other at all and only one has any communication with the client. In a one server, many client arrangement any client can communicate with all the other clients via the server. In your arrangement one client communicates with one server and the rest might just as well not exist.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    13

    Re: Socket Multiple Connection VB.NET

    dunfiddlin thank you for your argument , this is surely helps to clear things up.

    I would like to note that I am NOT interested that clients could communicate with each others , that's why I used servers.

    Your soultion would be perfect if I was willing to create applications for Chats like LAN chat / IRC chat/ Games such as World of Warcraft as an example.
    that you have "one"-"shared-server" which perhaps has MySQL database which stores details of users and so on , and many clients to connect to that server.

    In my case , I would like NOT to use such a thing. there is NO communication among clients.
    The message to be sent from the client would be specifically to specifically server and no other servers would see the message,

    For example I would like to send different hash/md5 code to different computer
    so
    Computer #1 would recieve abcde232blahblah..
    Computer #2 would recieve soso13849232...

    Computer #1 could not commuincate with Computer #2 , also Computer #2 could not communicate with Computer #1


    Computer #1 & Computer #2 recieve special & diffrenet code from one Computer only which is the client.
    so they may act as servers and not as clients.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,864

    Re: Socket Multiple Connection VB.NET

    Are we have a language problem here???

    The SERVER is the central resource that communicates among many CLIENTS.

    This mimics a typical restaurant setting - a waiter (server) interacting with many customers (clients).

    Why are you switching the "names" and "rolls" around like this? That's not helping us understand what you really want to do at all...

    You last post - #5 - is really confusing...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,321

    Re: Socket Multiple Connection VB.NET

    Actually, I think I understand the last post better. In the first post, I thought that the client would connect to one server, then that server would share whatever it received with all the other servers, but post #5 makes it sound like the client may connect with server1 for one purpose, then connect with server2 for a different purpose, then connect with server3 for a third purpose, and so on. Seems like an excess of hardware, but if all the servers play different roles, and the client interacts with each one in a unique way, then that's fine.

    On the other hand, if that is right, I've forgotten what the question was....
    My usual boring signature: Nothing

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,864

    Re: Socket Multiple Connection VB.NET

    Quote Originally Posted by Shaggy Hiker View Post
    On the other hand, if that is right, I've forgotten what the question was....
    Ha!

    Actually one of the app's I've been working on has "4 services" - and a client that can talk to "two" of them. These services in the background communicate with each other as well.

    I did this for scalability - so that I could in fact run the services on different physical boxes.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    13

    Re: Socket Multiple Connection VB.NET

    szlamany let us make things more easier than talking about therois.
    forget about clients , forget about server, forget about sockets..
    Okay?

    I need an algorithm / pseudo code that sends different number to diffrenet computers in lan network.

    SO SIMPLE :
    Having three computers in lab. connected to same router / same network / same domian whatever.

    Computer #1
    Computer #2
    Computer #3

    Computer #1 sends the number "2" to computer 2. then Computer #1 sends the number "3" to computer 3.

    How is that being done?

  10. #10
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Re: Socket Multiple Connection VB.NET

    If I may add a thought here. I too am looking at doing some P2P communication and in searching for information and asking questions I find that far too many people think of a chat program when this subject comes up. I think the OP may be trying to do the same thing I'm looking to do which is kind of specialized and definitely not a chat program. In my case, I want a bunch of clients to communicate with the same server. But all I want to do is to send a stream of data which gets parsed and processed when the server receives it. The server will of course send a reply back to the client to let them know it succeeded or failed.

    Well today I found several examples of P2P apps, and again most of them were about how to setup a chat app. And lots of what looks promising will not work well because its an older VB6 or VB5 code set. A couple of them peaked my interest but so far I still have to keep looking and experimenting. There are some nice examples on the msdn site using TcpListener class. Just search on the msdn site and you'll find them.

  11. #11
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,864

    Re: Socket Multiple Connection VB.NET

    @vladamir - I do exactly that using HTTP listener class to ship posts of data to various server apps.

    I utilized multi-threading to allow for many requests being processed at the same time - maybe that's what the OP is looking for.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width