Skip to content

Instantly share code, notes, and snippets.

@KennethanCeyer
Created October 1, 2015 01:24
Show Gist options
  • Save KennethanCeyer/77015af6ecc7dd924eb9 to your computer and use it in GitHub Desktop.
Save KennethanCeyer/77015af6ecc7dd924eb9 to your computer and use it in GitHub Desktop.
C# Socket bind ip from the dns domain name.
IPAddress bnetServerIP = Dns.GetHostAddresses(bnetConInfo["ip"])[0];
IPEndPoint bnetServerEP = new IPEndPoint(bnetServerIP, Int32.Parse(bnetConInfo["port"]));
this.bnetSock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
byte[] receiveBuffer = new byte[255];
try
{
this.bnetSock.ReceiveBufferSize = Int32.MaxValue;
this.bnetSock.ReceiveTimeout = 3000;
this.getHandleMsg(BnetCode.ConnectionWithServer);
}
catch (Exception e)
{
this.getHandleMsg(BnetCode.ConnectionSuccess);
}
this.bnetSock.Connect(bnetServerEP);
this.bnetSock.Send(BitConverter.GetBytes(0x01));
this.getHandleMsg(BnetCode.ConnectionSuccess);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment