Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I Receive messages in my TCPClient without a TcpListener? I don't want my chat client to require port forwarding, Also, the TcpListener messes up the host with a error message saying there is already a listener on that port.
How do I accomplish this?
Posted

1 solution

The following is in c# - but it's about as simple as it gets.
Introduction to TCP client server in C#[^]

Without a TCPListener you have to actively poll the server for data, on its own, the TCPClient does not listen for incomming requests.

Use something like ThreadPool[^] to poll data from the server asynchronously, and remember to synchronize access from the worker thread with the UI thread - Another way to Invoke UI from a Worker Thread[^].

If you don't use threads your client will appear to hang while polling the server. Another option is to poll using asynch io - but that's usually considered harder to implement correctly - good luck :)

Update
Hopefully this article will guide you towards creating a satisfying solution:
A Chat Application Using Asynchronous TCP Sockets[^]

Regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Sandeep Mewara 12-Mar-11 8:22am    
Comment from OP:
I'm thinking of using my website as a host for a text file containing chat for a Server and it'll access a PHP file with a WebClient etc, It'll be slower but, I don't see any problem with that. :P Also, How can I do this Async Polling? I'd like to know and try.
maxter1999 12-Mar-11 10:05am    
I did it.
Sandeep Mewara 12-Mar-11 10:07am    
You did what? You posted your concerns to the answer as an new answer.

You need to use comment feature to respond to an answer.
You need to update your question(using Improve question link) to edit/add more to your question.
You need to start a new question for a new question.
Espen Harlinn 12-Mar-11 10:15am    
I hope "A Chat Application Using Asynchronous TCP Sockets" was useful :)
Sandeep Mewara 12-Mar-11 8:22am    
Good answer. My 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900