473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Socket - Need help for Multiple clients to server using VB.NET

Hi,

Let's say that I run this raw code. This is on a server side, the
server will wait for client connection request.

Private MyTcpListener As System.Net.Sockets.TcpListener
Private MySocket As Socket

Dim MyPort as int32
MyPort = 1000

Dim ipHostInfo As IPHostEntry = Dns.GetHostByName(Dns.GetHostName()) Dim
MyIPAddress As IPAddress = ipHostInfo.AddressList(0)
Dim localEndPoint As New IPEndPoint(MyIPAddress, MyPort)

MyTcpListener = New Net.Sockets.MyTcpListener(localEndPoint)
MyTcpListener.Start()

[...]

'Looping periodically on MyTcpListener to see if any client try to
' connect
If Not (MyTcpListener.Pending()) Then
Exit Sub
else
MySocket = MyTcpListener.AcceptSocket
End If

For a new connection MySocket will containt information about the new
client information (port, IP).

If I want many clients being able to connect to this server, do I have
to create an array of MySocket? Then any new accepted client would be
indexed (from i=0 to n, n=max connect allowed). That index would be
useful for me.

And I wouldn't have to care anymore with port number? Is that right?

How could I connect a "datareceive event" from any client?

Thanks you very much!
Jul 21 '05 #1
2 1385
Hi there
I don’t recommend you create an array instead think of creating a class
which will handle the connection with the client, and you can store each
client object in a hash table with the user name as the key. For more info
you can check .net 101 sample - How to use sockets

Anas H.

"User" wrote:
Hi,

Let's say that I run this raw code. This is on a server side, the
server will wait for client connection request.

Private MyTcpListener As System.Net.Sockets.TcpListener
Private MySocket As Socket

Dim MyPort as int32
MyPort = 1000

Dim ipHostInfo As IPHostEntry = Dns.GetHostByName(Dns.GetHostName()) Dim
MyIPAddress As IPAddress = ipHostInfo.AddressList(0)
Dim localEndPoint As New IPEndPoint(MyIPAddress, MyPort)

MyTcpListener = New Net.Sockets.MyTcpListener(localEndPoint)
MyTcpListener.Start()

[...]

'Looping periodically on MyTcpListener to see if any client try to
' connect
If Not (MyTcpListener.Pending()) Then
Exit Sub
else
MySocket = MyTcpListener.AcceptSocket
End If

For a new connection MySocket will containt information about the new
client information (port, IP).

If I want many clients being able to connect to this server, do I have
to create an array of MySocket? Then any new accepted client would be
indexed (from i=0 to n, n=max connect allowed). That index would be
useful for me.

And I wouldn't have to care anymore with port number? Is that right?

How could I connect a "datareceive event" from any client?

Thanks you very much!

Jul 21 '05 #2
This is very useful, thanks you !

Anas H. wrote:
Hi there
I don’t recommend you create an array instead think of creating a class
which will handle the connection with the client, and you can store each
client object in a hash table with the user name as the key. For more info
you can check .net 101 sample - How to use sockets

Anas H.

"User" wrote:

Hi,

Let's say that I run this raw code. This is on a server side, the
server will wait for client connection request.

Private MyTcpListener As System.Net.Sockets.TcpListener
Private MySocket As Socket

Dim MyPort as int32
MyPort = 1000

Dim ipHostInfo As IPHostEntry = Dns.GetHostByName(Dns.GetHostName()) Dim
MyIPAddress As IPAddress = ipHostInfo.AddressList(0)
Dim localEndPoint As New IPEndPoint(MyIPAddress, MyPort)

MyTcpListener = New Net.Sockets.MyTcpListener(localEndPoint)
MyTcpListener.Start()

[...]

'Looping periodically on MyTcpListener to see if any client try to
' connect
If Not (MyTcpListener.Pending()) Then
Exit Sub
else
MySocket = MyTcpListener.AcceptSocket
End If

For a new connection MySocket will containt information about the new
client information (port, IP).

If I want many clients being able to connect to this server, do I have
to create an array of MySocket? Then any new accepted client would be
indexed (from i=0 to n, n=max connect allowed). That index would be
useful for me.

And I wouldn't have to care anymore with port number? Is that right?

How could I connect a "datareceive event" from any client?

Thanks you very much!

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: User | last post by:
Hi, I tried to find the information over the internet but didn't find any answers. I'm looking for a server side code example of winsock accepting many clients. I know that in VB.NET it is...
6
by: Anders Both | last post by:
If you send data using TCP and Socket, can the client then be 100% sure that if it send´s data and no exception uccur, then the data will also arrived in a a correct way on the server. What if...
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
1
by: Ken Foster | last post by:
I have a Socket based application using the asynchronous Sends and Receives of the Socket class. I send out XML strings using BeginSend/EndSend from a client end point, the server side does a...
8
by: Ankit Aneja | last post by:
i am doing here some some socket-client work in C# windows service it is working fine for multiple clients now i want to limit these multiple clients to 25 for example i want that when service...
13
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
2
by: Macca | last post by:
Hi, I have written an asychronous socket based on the microsoft example below :- http://msdn2.microsoft.com/en-gb/5w7b7x5f.aspx My app is connected to multiple clients which connect to the...
14
by: DaTurk | last post by:
I am makeing a Multicast server client setup and was wondering what the difference is between Socket.Connect, and Socket.Bind. It may be a stupid question, but I was just curious. Because I...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.