Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Port listening 1

Status
Not open for further replies.

falled

Programmer
Nov 3, 2006
47
ES
Hi people!

Anyone knows how to listen to any port, I must build an application to communicate two computers. I thougth a good way to do it is using two ports in each computer. One listening and one is used to write. A bidirectional port should be a little hard (I don't know if it's possible xD)

Anyone can advise me a smart way to do it?

Can i simulate de communication with an only PC?

Thank you all!!!
 
Hi, the best classes to use is TCPListener (as the server), TCPClient (as the mmm, client), because they are easer to use.

There are some good examples in the help files included with vs.net. These examples helped me get started on my way to creating a web server and then an email server.

The normal setup is to have a server application (listener), and a client. They both can communicate with each other at the same time (without closing). UDP connections on the other hand, are talk one way then close and wait for a new connect for response. Best to stay away from UDP, as well as being hard to use it also can also be blocked by your firewall.

And yes you can communicate with the same computer, just use 'localhost' or '127.0.0.1' for the IP address.

The TCPListener starts the port(81 for example), then the TCPClient connects to the same port(81).

Big Note: Two listeners cannot listen on the same port (in windows). I will throw a nasty error if you try.

If you are still having problems starting off then come back to the thread, i sould have an example done by then.
 
Thank you for your time!! I'll search and try it immediatly
 
Well looking the examples I realize that maybe I should create a application with two threads.

One with the tcpclient and the other with the tcplistener.

The application must have at least three configurable fields:

Listen Port, Sending Port, ¿target IP?

I'll keep investigating!!!

correct me if you think I'm wrong please

Thank you all!!!!
 
You are correct. You want the listener and the sender to each be on their own threads. You'll also likely want them both to be seperate from the primary thread. So you'll have 3 threads running in total. The primary thread is started by your modMain or form that is set to be the primary start-up object. From there you will want to launch the two threads to handle the network communication.

Remember to use sync lock on any variables that are shared between the threads.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
This is getting hard....

I'll keep trying! Do you know any website with .Net thread examples like the one above?
 
There are a few FAQs here on threading that may help(See the FAQ link towards the top of the page). And I'm sure there are samples of the exact code you are looking for on the web, its just a matter of getting a search engine to share them ;)

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top