Sockets usage with vb.net

A

altaf.sunesara

Hello !

I have some devices which communicate trough LAN to the server the old
form i was using was FTP as a communication between Server and Client i
have decided to use personal TCP sockets instead of using the FTP
protocol. Well im familar with sockets but some concepts im not able to
get it. I would be using Vb.Net as a server program but the question
pampering my brain is for eg .. ip 192.168.0.0.1 tries to communicate
on the server port 5444 and at the same time another device with ip
192.168.0.0.2 tries to communicate on port 5444 what would be the
result in this case the device with ip x.x.x.1 is still using the port
will the other device can communicate on the same port .

Regards
Altaf
 
C

Crouchie1998

Don't you mean IP: 192.168.0.1 & not 192.168.0.0.1?

You can use one of the overloaded functions to pass a specific port number.
Just see the sockets class for information

Socket programming is greatly simplified with VB.NET

Crouchie1998
BA (HONS) MCP MCSE
 
C

Chris

Hello !

I have some devices which communicate trough LAN to the server the old
form i was using was FTP as a communication between Server and Client i
have decided to use personal TCP sockets instead of using the FTP
protocol. Well im familar with sockets but some concepts im not able to
get it. I would be using Vb.Net as a server program but the question
pampering my brain is for eg .. ip 192.168.0.0.1 tries to communicate
on the server port 5444 and at the same time another device with ip
192.168.0.0.2 tries to communicate on port 5444 what would be the
result in this case the device with ip x.x.x.1 is still using the port
will the other device can communicate on the same port .

Regards
Altaf

This is the basic concept:

You use one port to make a connection (port 5444 in this case) then you
open a new port at a random port number (the framework will pick a port
for you) This new port is the one all the communication is done on,
leaving port 5444 for the next connection.

Chris
 
K

Kai Zhang

This is the basic concept:

You use one port to make a connection (port 5444 in this case) then you
open a new port at a random port number (the framework will pick a port
for you) This new port is the one all the communication is done on,
leaving port 5444 for the next connection.

Chris

Sorry, but I thought only UDP connections needs to release the public port
(5444 in this case), and create a random port for communication. Is the
socket for TCP and UDP connection works in same way?

Please point me out if I am wrong. Thanks.

Kai
 
A

altaf.sunesara

Hello !
Thanks all for the reply....

Well i got the idea behind sockets more clearly....

Thanks once again.
 
A

Alex Clark

You use one port to make a connection (port 5444 in this case) then you
open a new port at a random port number (the framework will pick a port
for you) This new port is the one all the communication is done on,
leaving port 5444 for the next connection.

I'm not convinced this is true actually, at least not for TCP sockets. If
this is the case, then a webserver listening on port 80 has to create a new
socket listening on a random port each time a client connects, which
produces obvious problems with firewalls & routers.

I was under the impression you created an array of socket objects, adding to
the array each time a new client connected, but all set to the same port (or
perhaps port 0?). I could be wrong as I don't do much socket coding...

Kind Regards,
Alex Clark
 
T

Terry Olsen

It doesn't pose a problem with firewalls & routers. I'm sure someone will
correct me if i'm wrong, but this is my experience with sockets.

Client calls server on listener port (SMTP port 25 perhaps)
Server responds with a random port assignment (maybe port 9999)
This causes the router/firewall to "open" port 9999 (maybe limit it to the
client's IP)
The client responds back on port 9999 and data exchange can commence.
The server resumes listening for new connections on port 25.
 
A

Alex Clark

Hi,
It doesn't pose a problem with firewalls & routers. I'm sure someone will
correct me if i'm wrong, but this is my experience with sockets.

Client calls server on listener port (SMTP port 25 perhaps)
Server responds with a random port assignment (maybe port 9999)
This causes the router/firewall to "open" port 9999 (maybe limit it to the
client's IP)
The client responds back on port 9999 and data exchange can commence.
The server resumes listening for new connections on port 25.

I'm 99% certain firewalls & routers do NOT work that way, it would pose a
pretty huge security risk if they were to open ports like that based on the
request of a service within the network.

The server itself likely remaps the established connection to either a
random port or a "pseudo" port (ie port 0) and then resumes listening on
port 25 in your example, otherwise the routers would potentially have large
arrays of open ports on them during busy times.

Regards,
Alex Clark
 
T

Terry Olsen

I can only go by what I observe watching incoming TCP connections to my BBS.
I am inside a router. The BBS listens on port 9999 (I have the router
configured to send 9999 to my BBS's internal IP). When a user logs in, the
status screens shows a user connected on some random port such as port
19837. I don't have that port opened up on my router, but the
communications are not interrupted.

If the server "remapped" the connection to a random port, wouldn't the
actual connection still be on port 9999? If so, how would anyone else be
able to connect? When I telnet out to another site, I telnet to a specific
port (23 for instance). Once the connection is established, my client
program tells me I am connected to some random port like 1029.

So from my observations, my explanation makes the best sense to me.
 
A

Alex Clark

Hi Terry,

As I said, I'm certainly no socket expert! I think you're right with it
assigning to another random port - my experiences were from the "old" days
of VB6 Winsock programming. I believe once it's connected on the "true"
port, ie 25 for an SMTP server, the socket object referenced by handle is
then remapped to a new port number. Because it's already an established
TCP/IP connection, the router/firewall continues to let it through on the
new port.

Dang IP layer theories never did sit well with me, hehe!

Kind regards,
Alex Clark
 
A

altaf.sunesara

Hello !

Well i have also observed the same thing. The port binds itself to a
different port which can be seen using netstat -a command where the
address is bind to a foregin address i gone trough it i have some more
questions

I want to create a server program where Server listens to a specific
port take it 8000 there would be many clients who may need to connect
to this port same time so it's taken care and been discussed above, now
suppose one client ask's 1+1 to server and at same time other client
initates a connection and asks server 9*2 server is ready with answers
but the point is the answer needs to be send to specific client whom it
belongs the connection for both the clients is active how can we send
the answer back to the respective clients. I gone trought the
NetworkStream class in vb.net but still im confused how can this be
done.

Regards
Altaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top