|
Reposting the same question is not going to get a quicker answer
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Please can anyone help me with the codes on voice streaming of the following scenario...
I want to develop a code which can run on my PDAs making both of them to be able 2 communicate with each other over a network (the PDAs are wi-fi enabled)
Mode of communication is : 1. Voice calls
2. Text messaging
I intend to have a server (my laptop) which handles the whole of the switching process, and also is able to pass voice n data btw itself and the PDAs.
Scenario
Have two personal digital assistants ( PDAs) and my laptop which connect to each other over a network.
I need to develop a code which will help stream voice and data over the network, making the PDAs able to make voice calls to each other and also to my laptop which also acts as the server or switching system here.
The laptop helps to switch calls btw both parties and also help to initiate an end to call btw both parties.
The laptop also runs both the client aand server software.
The switching should be fast and effective...Compression of voice over the network is allowed.
Thanks
|
|
|
|
|
So what is the problem, what have you tried, what is stopping you from developing the code.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I've got 1 accepted connection from TcpClient in async TcpListener.
I read all data from the client and then close its connection. But it might not be closed as described in the previous post.
After I invoke Stop() in TcpListener it recieves async client connect message. Then in that handler the System.ObjectDisposedException in System.Net.Sockets.Socket EndAccept(System.IAsyncResult) happens with message access to destroyed object is prohibited. object name "System.Net.Sockets.Socket"
What is the reason for that?
private void TcpListenerClientConnectAsyncCallback(IAsyncResult ar)
{
TcpListener tcpListener = (TcpListener)ar.AsyncState;
TcpClient tcpClient = this.tcpListener.EndAcceptTcpClient(ar);
NetworkStream ns = tcpClient.GetStream();
ns.BeginRead(buffer, 0, 1024, new AsyncCallback(TcpListenerDataReadAsyncCallback), tcpClient);
tcpListener.BeginAcceptTcpClient(new AsyncCallback(TcpListenerClientConnectAsyncCallback), tcpListener);
}
Also is there a way to notify the TcpListener that the TcpClient disconnected from its side? as in C++ winsock using windows messages FD_ACCEPT, FD_READ, ... ?
Чесноков
|
|
|
|
|
Before closing listener, you need to send a message to all connected clients indicating the exit. Clients should accept this message and disconnect itself. Once all the clients are disconnected, it is safe to close the listener.
Best wishes,
Navaneeth
|
|
|
|
|
That is great of adding additional messages with TcpClient/TcpListener classes. It sounds wierd to add specific messages to be processed by them to indicate they are due to close
In any case, I close the connection from client to server and from server to client by closing NetworkStream first and then the TcpClient.
tcpClient.GetStream().Close();
tcpClient.Close();
It does not affect them in either way, still producing those ClientAccept message to server
Are there better ways to work with Socket class instead of that Tcp abstraction?
Чесноков
|
|
|
|
|
It looks like you are new to network programming. I'd suggest to stay away from asynchronous methods for now. Spawn new threads or use ThreadPool to do the work. Once you feel comfortable with that design, try for asynchronous method. Manually creating threads and using it for handling connections and messages works well. You need asynchronous methods only when you need high scalability.
That said, there is no method to stop the asynchronous call especially when the call involves unmanaged code execution. A call to EndAccept will not help as it waits until the operation completes.
Chesnokov Yuriy wrote: Are there better ways to work with Socket class instead of that Tcp abstraction?
It depends on what you are doing. If you are doing for learning, TcpListener and TcpClient should be enough. For any serious network programming work with Socket class directly. This[^] MSDN article may help you.
Best wishes,
Navaneeth
|
|
|
|
|
No. I'm new to C# sockets.
I was coding async sockets in C++ before with winsock. It has windows handle to process all connection/disconnection etc... messages
Internet Traffic Firewall and Sniffer[^]
MFC Telnet Application[^]
C# sockets in async mode are quite different
Чесноков
modified on Sunday, November 1, 2009 6:51 AM
|
|
|
|
|
BTW if no clients have been connected to the TcpListener, that ClientConnect message still happen???
Чесноков
|
|
|
|
|
Do you mean TcpListenerClientConnectAsyncCallback method will get called if no clients connected? It will not get called when there are no connections.
Best wishes,
Navaneeth
|
|
|
|
|
Yes. After I call Stop() method on TcpListener.
Чесноков
|
|
|
|
|
How to notify TcpClient that it is disconnected?
1. I start async TcpListener
2. Once the client is connected it reads all data it sent also in async mode
3. Then simply close NetworkStream and close the client connection
private void TcpListenerDataReadAsyncCallback(IAsyncResult ar)
{
TcpClient tc = (TcpClient)ar.AsyncState;
NetworkStream ns = tc.GetStream();
ns.Close();
tc.Close();
}
In the client console, I wait in the loop with small sleeps for a long long while to wait if the server will send somthing, testing tcpClient.Connected property.
But it never becomes false???
Чесноков
|
|
|
|
|
Polling is one way to identify the listener status. You have to send a message to server and check the delivery status. If message got delivered successfully, server is connected.
Best wishes,
Navaneeth
|
|
|
|
|
Sending the message will induce the listener to recieve it and process.
In the listener I handle specific messages. It will need to process then connection test message in addition?
Do I need to insert additional sending of some data in that loop? with NetworkStream
for (int i = 0; i < 10 * 5; i++)
{
if (networkStream.DataAvailable == true)
{
}
Thread.Sleep(100);
if (tcpClient.Connected == false)
{
break;
}
}
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: In the listener I handle specific messages. It will need to process then connection test message in addition?
Yes. It can just process this message and acknowledge back.
Best wishes,
Navaneeth
|
|
|
|
|
Hi..!!
i add the paint event and both the shapes will be drawn on the form when i
run the progra, just in case if the statement of radio buttons or if() statements are not present. if i write them it don't give any error but only square comes on screen.
if i put this code on form_load then e.graphics is not recognized.what should i do...?????? don't know..plz reply if sumbdy knows...thanxx..
private void Shapes_Paint(object sender, PaintEventArgs e)
{
if (Square.Checked == true)
{
e.Graphics.DrawRectangle(Pens.Blue, 180, 80, 80, 80);
}
if(Triangle.Checked == true)
{
e.Graphics.DrawPolygon(Pens.Red, new Point[] { new
Point(300, 150), new Point(400, 250), new Point(200,250) });
}
}
|
|
|
|
|
Tip: Look at the PRE tags
The e.Graphics field is a Graphics type. To get an instance of this, set the Form's BackgroundImage property to a new Bitmap , passing the Form's ClientHeight and ClientWidth parameters. Then use your normal DrawXXX methods on the result returned from Graphics.FromImage(YourForm.BackgroundImage)
modified on Sunday, November 1, 2009 3:39 AM
|
|
|
|
|
0x3c0 wrote: Tip 2: Use plain English
That's a bit rude. The poster is obviously someone whose first language is not English, but has still tried hard to make their question clear.
|
|
|
|
|
I was a touch cranky last night to be honest. I'm not too happy with the way that sounds, and I agree it was rude. Edited
|
|
|
|
|
It's a trap we can all fall into quite easily - I'm as guilty as anyone. I make it a rule now always to use the preview button on my replies and read through a couple of times before I post. And then I re-read it after posting just in case.
The good thing about these forums is that not only do we police the spammers, but also each other.
|
|
|
|
|
Hi,
you are right, all painting should be done in the Paint handler.
however if your drawing isn't to be constant, you should call Invalidate() when a change is needed.
So here, add CheckedChanged handlers to your checkboxes and have them call Invalidate; you may even share such a handler for many Controls.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
thanx..i got it and iots working now..
|
|
|
|
|
you're welcome.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
iwant to write CSMA/CD with c#
|
|
|
|
|
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|