Hi Guyz
well I wanna implement a tcp chat program with C# and winsock, and I know
that I should use Asynchronous methods so my windows program won't be
blocked, but in my application both clients could send and receive messages
at the same time, which means I can not begin recieving after sending a
message or vice versa, it's possible that my application would recieve
multiple messages, so how should I handle that?
Regards, 3 3401
Hola Jefe,
"Jefe" <Je**@discussio ns.microsoft.co m> wrote in message
news:E2******** *************** ***********@mic rosoft.com... Hi Guyz well I wanna implement a tcp chat program with C# and winsock, and I know that I should use Asynchronous methods so my windows program won't be blocked
not really, you can use a thread that send/receive info, once it gets/send
the info it send an event to the UI thread. IMO this is the easiest approach
, but in my application both clients could send and receive messages at the same time,
You could use two threads, one for send and another to receive, you will
have to make sure that there is no concurrency conflict though.
An easier solution is to use one thread only and in a loop check for data to
send, send it, check for data received, receive it and notify the UI and
repeat the loop again.
which means I can not begin recieving after sending a message or vice versa, it's possible that my application would recieve multiple messages, so how should I handle that?
No multiple messages, you have to receive them sequentially.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jefe,
if you check this sample google search http://www.google.com/search?hl=en&q...%22tcp+chat%22
You will see that there are numerous implementations of chat that you can
study.
You do not need to use Winsock directly in C# as the .NET classes provide
this functionality for you.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Jefe" wrote: Hi Guyz well I wanna implement a tcp chat program with C# and winsock, and I know that I should use Asynchronous methods so my windows program won't be blocked, but in my application both clients could send and receive messages at the same time, which means I can not begin recieving after sending a message or vice versa, it's possible that my application would recieve multiple messages, so how should I handle that? Regards,
| You could use two threads, one for send and another to receive, you will
| have to make sure that there is no concurrency conflict though.
That is the way I would go. Have two threads - sender and receiver
contained in your Chat Class. GUI has nothing to do with it at this point.
Your sender will block on a blocking circular queue (i.e. my one lock
blocking CQ on codeproject) and when it gets a post, it sends. Likewise
your receiver will block on networkstream.R ead() and enque into receiver
queue. You could then do a gui ThreadWorker that blocks on receive queue
and posts to your textbox.
--
wjs This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Niels Borg |
last post by:
Hi,
I'm writing app where I use WinSock, but I have experienced a problem.
WinSock only sends the data after finishing the calling sub/function. Can I
force WinSock immediately as I need to send several packets but they have to
be sent separate?
Many thanks
Niels Borg
|
by: Ophir |
last post by:
Hello all !
I wrote a simple ActiveX DLL to wrap winsock functionality so I can
use it in an ASP page.
I call it MyWinSock
In the Class module I use this declaration:
Dim ctlSocket as Variant.
|
by: Chris Thompson |
last post by:
I'm trying to mess around with creating a multi-user server but I'm really
clueless as to how to start. I don't know what I'd need to do, and more than
likely it's over my head, but I'd still like to mess around. If anybody
could point me in the right direction it would be greatly appreciated.
|
by: Bill |
last post by:
When vb6 Winsock.RemoteHost is set to "127.0.0.1", c# socket listener cannot hear connect request (my old vb6 winsock listener could hear it...).
Why doesn't this work, and is there a work around I can make on the C# side to hear the connect request?
-Bill
(don't reply by e-mail, the address is a fake)
______________________________
Steps to reproduce:
Start the C# Listener
|
by: Yu Chai |
last post by:
Hi guys,
I created a ASP page that
1. users can run when WinSock proxy are using (ie's one is unchecked)
2. users can't run when WinSock proxy are using (ie's one is checked)
3. users can't run when WinSock proxy are not using (ie's one is checked)
4. users can't run when WinSock proxy are not using (ie's one is unchecked)
So, what is the difference between winsock proxy client and the proxy
setting in browser (IE)?
| |
by: Nadav |
last post by:
Hi
I am writing some kind of a storage system that have to deal with large amounts of data passing over the net, Now, I Wonder... traditional programming would use win32 Winsock DLL as the means of data transportation... now, indigo is the new communication layer of the CLR,
- Does indigo uses Winsock internally?
- Is it possible to use indigo for such a task?
- I assume using indigo has it's performance penalty ( doesn't it ?
- Does...
|
by: kc |
last post by:
Hi
Just upgrading a app from VB6 to VB.Net. All is going well apart from the
Winsock control.
The first thing we notice is that there does not appear to be a .Net version
(please correct me if wrong).
Also when we use the VB6 winsock control in a dotnet version we appear to
lose the ability of creating an array on winsock's.
for example we cannot assign as thus
|
by: Nicolas Ghesquiere |
last post by:
Hello
I have a problem with my current program.
The meaning of the program is to allow users to login to a server to allow
them to access the internet.
My program communicates with a MS isa server to make a rule for that IP for
the time-credits left for that user.
My problem is that so far, the program can handle everything except more
then one client, and i have done my best, but i can't find a decent solution
|
by: imaloner |
last post by:
I am posting two threads because I have two different problems, but both have the same background information.
Common Background Information:
I am trying to rebuild code for a working, commercially sold application with only partial build instructions. The previous maintainer of the code (a
mixture of C and C++) is no longer with the company, but when he built the code he used MSVC++, and though I am not certain of the version he was ...
|
by: AaronL |
last post by:
Hello,
I am currently working on a project that has me in sort of a bind. What I want to do is retrieve web pages from the internet, and strip them down to just text. I'll get using Regular Expressions to strip out the HTML code itself, the problem is actually getting the web pages from the internet.
I tried using the Microsoft Internet Transfer Control but my client was experiencing problems with some web pages not downloading, this...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |