Example #1
0
        public void SendMsgToServer()
        {
            Console.WriteLine("Input your msg to be sent to server:");
            var    userInput = Console.ReadLine();
            TxtMsg txtMsg    = new TxtMsg(userInput, UserService.LoginUserName);

            txtMsg.Send(serverSock);
        }
Example #2
0
        private void SendToAllClients(string txt)
        {
            if (tcp.AcceptedSockets == null || tcp.AcceptedSockets.Count == 0)
            {
                Console.WriteLine(">No client available");
                return;
            }
            TxtMsg txtMsg = new TxtMsg(txt, "Server");

            foreach (var sock in tcp.AcceptedSockets)
            {
                txtMsg.Send(sock);
            }
        }
Example #3
0
        public void SendTxtToFriend(string friend, string msg)
        {
            var f = CheckFriend(friend);

            if (f == null)
            {
                return;
            }
            var ip = f.IPEnd.Address;

            //client.SendMsgToServer();

            Socket udpSock    = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            var    remotenEnd = new IPEndPoint(ip, UDP_PORT);

            udpSock.Connect(remotenEnd);
            TxtMsg txt = new TxtMsg(msg, UserService.LoginUserName);

            txt.Send(udpSock);
        }