/// <summary> /// Make connection to the Rserve. /// </summary> public void Connect() { s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress address = IPAddress.Parse(host); Byte[] dane = new Byte[32]; Int32 recvCount = 0; try { IPEndPoint endPoint = new IPEndPoint(address, port); s.Connect(endPoint); recvCount = s.Receive(dane, 32, SocketFlags.None); //receive data from host receivedBytesCount += 32; } catch (Exception ex) { throw new RconnectionException(ex.Message); } if (recvCount != 32) { throw new RconnectionException("Handshake failed: expected 32 bytes header, got " + recvCount.ToString()); } /* checking that the response from Rserve is correct */ String receivedID = ASCIIEncoding.ASCII.GetString(dane, 0, dane.Length); if (String.Compare(receivedID, 0, myID, 0, 4) != 0) { throw new RconnectionException("Invalid IDstring"); } if (String.Compare(receivedID, 8, myID, 8, 4) != 0) { throw new RconnectionException("Protocol not supported"); } rserveVersion = Convert.ToInt32(receivedID.Substring(4, 4)); /* authentication checking */ Int32 pos = 16; while (pos <= 27) { String tmp = receivedID.Substring(pos, 4); if (String.Equals(tmp, "ARuc")) { authReq = true; ARtype = authTypes.crypt; key = receivedID.Substring(pos + 5, 3); } if (String.Equals(tmp, "ARpt")) { if (!authReq) { authReq = true; ARtype = authTypes.plain; } } pos += 4; } }