Membru care solicită informaţii
So, I'm trying to modify messenger, which i found here
The problem is, when I kill one of the clients is killed in task manager (simulating situation that internet dies or something like that), and I try to send message from another client
Here is the codehttp://pastebin.com/JR5vq22i
So, what I have done: I tried to catch exception at server.SendTo, wo when it crashes I remove the client from iplist
But then another exception appears here: receive = server.ReceiveFrom(data, ref klient);
Which is kinda weird, because klient (client, I kinda mixed languages when naming :() was removed from listaip, so it shouldn't crash here...
When I catch exception here, server console starts to SPAM "Waiting for message" text. It REALLY spams console.
After that I can't send any message from another client.
The exception is "An existing connection was forcibly closed by the remote host"
If you need client code too, just tell me, I could upload whole project somewhere if needed
27 mai 2011 08:01
- Mutat de Aspen VJ 30 mai 2011 06:12 (From:Visual C# General)
Here are some notes which may help:
1) Yes, you're removing klient from listaip but your ReceiveFrom() line is using a new EndPoint...not one from your list. What you should do here is if there's an exception in ReceiveFrom(), catch it and use continue to go back to the beginning of the while loop...so that you can start listening for another packet.
2) There's no reason to keep recreating the byte every time the while loop executes...that just generates garbage for the garbage collector. You can simply call Array.Clear() at that point int the loop instead.
3) UDP is an unreliable transport protocol which I assume you know. For a chat room that seems odd because it would suck to drop packets (and conversation)...and coding up a send/acknowledge system in UDP may be more effort than just using TCP.
Without seeing the entire project and being able to test it out locally it's going to be hard to determine why it's spamming (if it still does after you fix #1). If you decide to upload it somewhere I can take a look at it tomorrow...it's 4:20 AM here :)
ShaneB28 mai 2011 08:20
Based on your description, your issue is more related to Messenger Development. So I wll move this thread to Windows Live Messenger Client: Development. As that forum it talks about developer topics related to Messenger activities. Thanks for understanding.
Vin Jin [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
30 mai 2011 06:11
sorry, I was out whole weekend so couldn't answer you :)
here is whole project (trust me, no viruses :))
ConsoleApplication is server
WindowsForm is client
I've used your tip #1, and it works. But in debug mode, after killing one client, server starts lagging (but not losing packets), but it works fine using exe files.
I've found this project on the net, but it's bugged as hell, made a mistake of not writing my own code all by myself. Now I'm trying to make it work :)
#2 advice, done
It's a school project, there will be 5 clients max I think, so maybe udp won't fail :) if it won't work I will make it tcp
Now I found new bug, which bothers me a bit.
When I open client, but server is not running and I click join - client crashes.
How can I check if server is running?31 mai 2011 08:54
Since UDP is a connectionless protocol, I believe you'll have to trap the SocketException in your Receive method. If it were TCP you could just check the Connected property. Of course, to make things easier you may want to just use the UDPClient class...I'm sure you can find some good examples of using it on CodeProject.com :)
ShaneB31 mai 2011 18:23