Advertisement
Guest User

Socket in C#

a guest
Jan 7th, 2012
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. private void loginb_Click(object sender, EventArgs e)
  2.         {
  3.  
  4.             String username = this.textBox1.Text;
  5.             String password = textBox2.Text;
  6.  
  7.             String server;
  8.             if (username.Equals("Lolmewn"))
  9.             {
  10.                 server = "localhost";
  11.             }
  12.             else
  13.             {
  14.                 server = "77.251.20.228";
  15.             }
  16.             //start connecting
  17.             Encoding ASCII = Encoding.ASCII;
  18.             Byte[] RecvBytes = new Byte[256];
  19.             IPEndPoint hostEndPoint;
  20.             IPAddress hostAddress = null;
  21.             int conPort = 3456;
  22.  
  23.             // Get DNS host information.
  24.             IPHostEntry hostInfo = Dns.GetHostEntry(server);
  25.             // Get the DNS IP addresses associated with the host.
  26.             IPAddress[] IPaddresses = hostInfo.AddressList;
  27.  
  28.             // Evaluate the socket and receiving host IPAddress and IPEndPoint.
  29.             for (int index = 0; index < IPaddresses.Length; index++)
  30.             {
  31.                 hostAddress = IPaddresses[index];
  32.                 hostEndPoint = new IPEndPoint(hostAddress, conPort);
  33.                 Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  34.                 if (!s.Connected)
  35.                 {
  36.                     continue;
  37.                 }
  38.                 s.Send(ASCII.GetBytes("un=" + username + ";pw=" + password));
  39.                 Int32 bytesGet = s.Receive(RecvBytes, RecvBytes.Length, 0);
  40.                 String get = ASCII.GetString(RecvBytes, 0, bytesGet);
  41.                 if (!get.Equals("allow"))
  42.                 {
  43.                     return;
  44.                 }
  45.                 else
  46.                 {
  47.                     loginb.Visible = false;
  48.                 }
  49.             }
  50.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement