Click here to Skip to main content
15,907,906 members

Comments by nie_trzeba (Top 6 by date)

nie_trzeba 20-Jan-17 9:11am View    
Oh okay, i got it! Thanks very much for all your advise! I'll try to research more on this protocol. Thanks!
nie_trzeba 20-Jan-17 8:44am View    
Thank you very much! And once again please (i promise!), i'll tried bind() method again on UDP protocol, there has a SendTo() method, that sending message without Connect(), so i tried to Bind() it to specified port only once, at beggining and then just call SendTo() method, and i don't know, but looks like it's working! I mean, after each sending i wright at console LocalEndPoint, and it showing me the one, that i specify at bind. How did you think, is my program works fine now, and is it really sending messages from one port ? Here is the code:
        
static void UDPMessage()
        {
            
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("10.11.2.147"), Convert.ToInt32("17000"));
            Socket s = new Socket(endPoint.Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp);

            IPEndPoint myPoint = new IPEndPoint(IPAddress.Parse("10.11.2.147"), Convert.ToInt32("61000"));

            try
            {
                byte[] msg = Encoding.Unicode.GetBytes("hello");

                s.Bind(myPoint);
                s.SendTo(msg, SocketFlags.None, endPoint);
                Console.WriteLine(s.LocalEndPoint.ToString());
                s.SendTo(msg, SocketFlags.None, endPoint);
                Console.WriteLine(s.LocalEndPoint.ToString());
                s.SendTo(msg, SocketFlags.None, endPoint);
                Console.WriteLine(s.LocalEndPoint.ToString());
                s.SendTo(msg, SocketFlags.None, endPoint);
                Console.WriteLine(s.LocalEndPoint.ToString());
            }
            catch
            {

            }
            finally
            {
                Console.ReadLine();
            }
        }
nie_trzeba 20-Jan-17 8:06am View    
Excuse me again, i wanna ask one more question, if we will not bind our client socket, how server will get know where to send back message ?
nie_trzeba 20-Jan-17 7:47am View    
Thank you very much for your answer! I will try to describe and prove this to my boss. Thank you for your help !
nie_trzeba 20-Jan-17 7:10am View    
Really weird, cause so many things that help others didn't help at my case. Maybe just my arms grow from the wrong side ? :)

I never heard about that, so i googled about it, and tried to make just like at that link https://www.experts-exchange.com/questions/21014265/PInvoke-winsock-WSAStartup-and-WSACleanup-in-c.html , but unfortunatelly it's didn't help too.

I asked my boss why he want it, and his answer was quite reasonable. The point is that we are making a server, that we will sell later to companies, and he afraid, that at some PC's firewall may be blocked some ports, and system couldn't choose the right one without bind, and message couldn't be send. I really bad at firewalls or etc so it was sounds true for me.

Anyway, thanks very much for your trying and wasted time on me, it's really cool :)