473,324 Members | 2,268 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,324 software developers and data experts.

VB.NET Socket - Multiple clients to server

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 not implemented like in VB6. What
I've done is one client per socket. Meaning that each client used a
different port on the server, but I find it annoying.

I would like to have all clients to connect to the server using one port.

How can I do that? Where can I find an example?

Thank very much!

Jul 21 '05 #1
9 3516
User <gu***@guest.com> wrote:
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 not implemented like in VB6. What
I've done is one client per socket. Meaning that each client used a
different port on the server, but I find it annoying.

I would like to have all clients to connect to the server using one port.


Just because they're using different sockets doesn't mean that clients
have to connect to different ports. Just use TcpListener and call keep
AcceptTcpClient or AcceptSocket and everything will be fine.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
I thought that a port number was unique to one socket? Is that right?

In my implementation, I use the port number as an identifier for the
client connection. If I use one socket, is there a unique identifier
for any accepted connection?

Thank you!

Jon Skeet [C# MVP] wrote:
User <gu***@guest.com> wrote:
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 not implemented like in VB6. What
I've done is one client per socket. Meaning that each client used a
different port on the server, but I find it annoying.

I would like to have all clients to connect to the server using one port.

Just because they're using different sockets doesn't mean that clients
have to connect to different ports. Just use TcpListener and call keep
AcceptTcpClient or AcceptSocket and everything will be fine.


Jul 21 '05 #3
In TCP communications, the listener application binds to an advertised port.
When a client connects to that port, the IP Stack sends a port number to the
server. The "accept" call binds that port as well as a new port on the
server and then sends back the new port on the server. Basically what
happens is that the communications link is taken to a random port pair - one
on the client and one on the server. Accept then resets the listener to
wait for the next connection request. To keep track of your clients, you
simply need to keep track of the sockets used by accept.

Mike Ober.

"User" <gu***@guest.com> wrote in message
news:OPJUc.25312$X12.22077@edtnps84...
I thought that a port number was unique to one socket? Is that right?

In my implementation, I use the port number as an identifier for the
client connection. If I use one socket, is there a unique identifier
for any accepted connection?

Thank you!

Jon Skeet [C# MVP] wrote:
User <gu***@guest.com> wrote:
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 not implemented like in VB6. What
I've done is one client per socket. Meaning that each client used a
different port on the server, but I find it annoying.

I would like to have all clients to connect to the server using one
port.

Just because they're using different sockets doesn't mean that clients
have to connect to different ports. Just use TcpListener and call keep
AcceptTcpClient or AcceptSocket and everything will be fine.

Jul 21 '05 #4
User <gu***@guest.com> wrote:
I thought that a port number was unique to one socket? Is that right?
I can't remember exactly how it works, but I believe there's the port
number as far as the client is concerned, and the "internal" port
number. One external port number can have many sockets connected, each
with a different "internal" port number.

I could be very wrong though. Hopefully someone who's looked at the
details more recently than me can give more accurate information.
In my implementation, I use the port number as an identifier for the
client connection.
Not a good idea, I suspect.
If I use one socket, is there a unique identifier for any accepted
connection?


There's the Socket object itself...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5
A socket is unique with 4 pieces of info:
1) server ip
2) server port
3) client ip
4) client port

So you have many sockets all connecting to same server ip and port as long
as client ip/port is different, which they will be. If the same client trys
to connect with same local port twice, it will fail locally trying to grab a
local socket that is using same ip and port (IIRC).

--
William Stacey, MVP

"User" <gu***@guest.com> wrote in message
news:OPJUc.25312$X12.22077@edtnps84...
I thought that a port number was unique to one socket? Is that right?

In my implementation, I use the port number as an identifier for the
client connection. If I use one socket, is there a unique identifier
for any accepted connection?

Thank you!

Jon Skeet [C# MVP] wrote:
User <gu***@guest.com> wrote:
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 not implemented like in VB6. What
I've done is one client per socket. Meaning that each client used a
different port on the server, but I find it annoying.

I would like to have all clients to connect to the server using one
port.

Just because they're using different sockets doesn't mean that clients
have to connect to different ports. Just use TcpListener and call keep
AcceptTcpClient or AcceptSocket and everything will be fine.


Jul 21 '05 #6
Let's say that I run this raw code.

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 would I connect a "datareceive event" from any client?

Thanks you!



Michael D. Ober wrote:
In TCP communications, the listener application binds to an advertised port.
When a client connects to that port, the IP Stack sends a port number to the
server. The "accept" call binds that port as well as a new port on the
server and then sends back the new port on the server. Basically what
happens is that the communications link is taken to a random port pair - one
on the client and one on the server. Accept then resets the listener to
wait for the next connection request. To keep track of your clients, you
simply need to keep track of the sockets used by accept.

Mike Ober.

"User" <gu***@guest.com> wrote in message
news:OPJUc.25312$X12.22077@edtnps84...
I thought that a port number was unique to one socket? Is that right?

In my implementation, I use the port number as an identifier for the
client connection. If I use one socket, is there a unique identifier
for any accepted connection?

Thank you!

Jon Skeet [C# MVP] wrote:

User <gu***@guest.com> wrote:
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 not implemented like in VB6. What
I've done is one client per socket. Meaning that each client used a
different port on the server, but I find it annoying.

I would like to have all clients to connect to the server using one
port.

Just because they're using different sockets doesn't mean that clients
have to connect to different ports. Just use MyTcpListener and call keep
AcceptTcpClient or AcceptSocket and everything will be fine.



Jul 21 '05 #7
Let's say that I run this raw code.

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 would I connect a "datareceive event" from any client?

Thanks you!

Jul 21 '05 #8
Let's say that I run this raw code.

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 would I connect a "datareceive event" from any client?

Thanks you!

Jul 21 '05 #9
gfx
hi,

u can have only one socket for a port which can listen for
all the incoming data on that port. try looking for
function read and readFrom in system::net::sockets
-----Original Message-----
Hi,

I tried to find the information over the internet but didn't find anyanswers.

I'm looking for a server side code example of winsock accepting manyclients. I know that in VB.NET it is not implemented like in VB6. WhatI've done is one client per socket. Meaning that each client used adifferent port on the server, but I find it annoying.

I would like to have all clients to connect to the server using one port.
How can I do that? Where can I find an example?

Thank very much!

.

Jul 21 '05 #10

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

Similar topics

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...
8
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...
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...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.