示例#1
0
        static void Main(string[] args)
        {
            LahoreSocketClient client       = new LahoreSocketClient();
            string             strIPAddress = MyServer.ipAddr;
            string             strPortInput = MyServer.mPort.ToString();

            if (!client.SetServerIPAddress(strIPAddress))
            {
                Console.WriteLine(strIPAddress, "is the wrong IP Address");
            }
            else if (!client.SetPortNumber(strPortInput))
            {
                Console.WriteLine(strPortInput, "is the wrong port number");
            }
            else
            {
                client.ConnectToServer();
                string strInputUser = null;
                do
                {
                    strInputUser = Console.ReadLine();
                    if (!(strInputUser.Trim().Equals("<EXIT>")))
                    {
                        client.SendToServer(strInputUser);
                    }
                    else
                    {
                        client.CloseAndDisconnect();
                    }
                }while (!(strInputUser.Trim().Equals("<EXIT>")));
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            LahoreSocketClient client = new LahoreSocketClient();

            client.RaiseTextReceivedEvent  += HandleTextReceived;
            client.RaiseServerDisconnected += HandleServerDisconnected;
            client.RaiseServerConnected    += HandleServerConnected;

            Console.WriteLine("*** Welcome to Socket Client Starter Example by Naeem Akram Malik ***");
            Console.WriteLine("Please Type a Valid Server IP Address or hostname formatted as <HOST> and Press Enter: ");

            string strIPAddress = Console.ReadLine();

            Console.WriteLine("Please Supply a Valid Port Number 0 - 65535 and Press Enter: ");
            string strPortInput = Console.ReadLine();

            if (strIPAddress.StartsWith("<HOST>"))
            {
                strIPAddress = strIPAddress.Replace("<HOST>", string.Empty);
                strIPAddress = Convert.ToString(LahoreSocketClient.ResolveHostNameToIPAddress(strIPAddress));
            }

            if (string.IsNullOrEmpty(strIPAddress))
            {
                Console.WriteLine("No IP Address Supplied...");
                Environment.Exit(0);
            }

            if (!client.SetServerIPAddress(strIPAddress) ||
                !client.SetPortNumber(strPortInput))
            {
                Console.WriteLine(
                    string.Format(
                        "Wrong IP Address or port number supplied - {0} - {1} - Press a key to exit",
                        strIPAddress,
                        strPortInput));
                Console.ReadKey();
                return;
            }

            client.ConnectToServer();

            string strInputUser = null;

            do
            {
                strInputUser = Console.ReadLine();

                if (strInputUser.Trim() != "<EXIT>")
                {
                    client.SendToServer(strInputUser);
                }
                else if (strInputUser.Equals("<EXIT>"))
                {
                    client.CloseAndDisconnect();
                }
            } while (strInputUser != "<EXIT>");
        }
 private void BtnSend_Click(object sender, EventArgs e)
 {
     if (client != null)
     {
         if (client.IsConnected)
         {
             client.SendToServer(tbTextToSend.Text);
         }
     }
 }
示例#4
0
        static void Main(string[] args)
        {
            LahoreSocketClient client = new LahoreSocketClient();

            client.RaiseTextReceivedEvent  += HandleTextReceived;
            client.RaiseServerDisconnected += HandleServerDisconnected;
            client.RaiseServerConnected    += HandleServerConnected;

            Console.WriteLine("*** Welcome to Socket Client Starter Example by Naeem Akram Malik ***");
            Console.WriteLine("Please Type a Valid Server IP Address and Press Enter: ");

            string strIPAddress = "89.229.95.152";

            Console.WriteLine("Please Supply a Valid Port Number 0 - 65535 and Press Enter: ");
            string strPortInput = "16010";

            if (!client.SetServerIPAddress(strIPAddress) ||
                !client.SetPortNumber(strPortInput))
            {
                Console.WriteLine(
                    string.Format(
                        "Wrong IP Address or port number supplied - {0} - {1} - Press a key to exit",
                        strIPAddress,
                        strPortInput));
                Console.ReadKey();
                return;
            }

            client.ConnectToServer();

            string strInputUser = null;

            do
            {
                strInputUser = Console.ReadLine();

                if (strInputUser.Trim() != "<EXIT>")
                {
                    client.SendToServer(strInputUser);
                }
                else if (strInputUser.Equals("<EXIT>"))
                {
                    client.CloseAndDisconnect();
                }
            } while (strInputUser != "<EXIT>");
        }
示例#5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.alternative_main);

            Button sendIt = FindViewById <Button>(Resource.Id.button1);

            phoneC       = FindViewById <EditText>(Resource.Id.editText1);
            nameC        = FindViewById <EditText>(Resource.Id.editText2);
            ip           = FindViewById <EditText>(Resource.Id.editText3);
            connectIt    = FindViewById <Button>(Resource.Id.connect);
            disconnectIt = FindViewById <Button>(Resource.Id.disconnect);
            int          counter       = 0;
            ToggleButton buttonCompany = FindViewById <ToggleButton>(Resource.Id.toggleButton2);

            self          = this;
            sendIt.Click += (sender, e) =>
            {
                string toadd = phoneC.Text + "|" + nameC.Text + "|" + buttonCompany.Text;
                //Toast.MakeText(ApplicationContext, toadd, ToastLength.Long).Show();
                Toast.MakeText(this, toadd, ToastLength.Short).Show();
                Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Νέος πελάτης : " + counter);
                alert.SetMessage(toadd);
                Dialog dialog = alert.Create();
                dialog.Show();
                counter += 1;
                Console.WriteLine(toadd);
                client.SendToServer(toadd);
                phoneC.Text = "";
                nameC.Text  = "";
                cust.Add(new Cust
                {
                    Name  = nameC.Text,
                    phone = phoneC.Text,
                });
                //BindingContext = this;
            };
            connectIt.Click    += connectToServerBtn;
            disconnectIt.Click += DisconnectBtn;
        }
示例#6
0
        static void Main(string[] args)
        {
            LahoreSocketClient client = new LahoreSocketClient();

            client.RaiseTextreceivedEvent += HandleTextReceived;

            Console.WriteLine("Welcome to socket Client Starter Eample :D");
            Console.WriteLine("Please type a valid server IP Address and press enter");

            string strIPAddress = "89.228.240.20";//Console.ReadLine();



            Console.WriteLine("Please Supply a Valid port Number 0 - 65335 and press Enter: ");
            string strPortInput = "16010";//Console.ReadLine();


            if (!client.SetServerIPAdress(strIPAddress) || !client.SetPortNumber(strPortInput))
            {
                Console.WriteLine("Wront IP Address or port nymber suppliet - {0} - {1} - Press a ke y to exit", strIPAddress, strPortInput);
                Console.ReadKey();
                return;
            }

            client.ConnectToServer();


            string strInputUser = null;

            do
            {
                strInputUser = Console.ReadLine();
                if (strInputUser.Trim() != "<EXIT>")
                {
                    client.SendToServer(strInputUser);
                }
                else if (strInputUser.Equals("<EXIT>"))
                {
                    client.CloseAndDisconnect();
                }
            } while (strInputUser != "<EXIT>");
        }
示例#7
0
        private void btnSendMessage_Click(object sender, RoutedEventArgs e)
        {
            SocketDataTransfer socketDataTransfer = new SocketDataTransfer(client_name, Globals.cmd_new_message, txtMessage.Text);

            client.SendToServer(socketDataTransfer);
        }