Example #1
0
        private Socket socket;// = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        public void Run(MainWindow CMW, CancellationToken pBacklineCanselToken)
        {
            clientMainWindow    = CMW;
            hostName            = Dns.GetHostName();
            hostEntry           = Dns.GetHostEntry(hostName);
            serverIPLocalv4     = hostEntry.AddressList.Last().MapToIPv4();
            backlineCanselToken = pBacklineCanselToken;

            while (!connected && !backlineCanselToken.IsCancellationRequested)

            {
                Thread.Sleep(1);
            }
            clientMainWindow.Set_Sys_Mes("Connected");
            while (!backlineCanselToken.IsCancellationRequested)
            {
                try
                {
                    socket.BeginReceive(Databuffer, 0, Databuffer.Length, SocketFlags.None, RecieveCallback, null);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            clientMainWindow.Dispatcher.InvokeAsync(clientMainWindow.EndAction());
        }
Example #2
0
 public void Connect()
 {
     try
     {
         socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         socket.BeginConnect(serverIPLocalv4, Vars.SERVER_PORT, ConnectionAccepted, null);
     }
     catch (SocketException)
     {
         clientMainWindow.Set_Sys_Mes("Socket exception");  // you can put a counter here to see how many attempts are made
     }
 }