public void Send(Connection con) { if (con.socket.Connected) { con.Send(1, amount.ToByteArray()); con.Receive(1); con.Send(1, id.ToByteArray()); con.Receive(1); con.Send(1, BitConverter.GetBytes(s_series.Count())); con.Receive(1); for (int i = 0; i < s_series.Count(); i++) { con.Send(1, s_series[i].ToByteArray()); con.Receive(1); con.Send(1, t_series[i].ToByteArray()); con.Receive(1); con.Send(1, u_hashes[i].ToByteArray()); con.Receive(1); con.Send(1, w_hashes[i].ToByteArray()); con.Receive(1); } Console.WriteLine("\t[debug]: Banknote sent."); } }
public void Receive(Connection con) { if (con.handler.Connected) { length = BitConverter.ToInt32(con.Receive(0), 0); con.Send(0, new byte[1]); values = con.Receive(0); con.Send(0, new byte[1]); } }
public void Send(Connection con) { if (con.socket.Connected) { con.Send(1, BitConverter.GetBytes(length)); con.Receive(1); con.Send(1, values); con.Receive(1); } }
public void EstablishConnectionWithAlice() { alice_connection = new Connection(); alice_connection.socket.Bind(alice_connection.ipEndPoint); Console.WriteLine("[info]: Waiting for connection..."); alice_connection.socket.Listen(1); alice_connection.handler = alice_connection.socket.Accept(); Console.WriteLine("[info]: Connection accepted."); }
public void Receive(Connection con) { if (con.handler.Connected) { var result = con.Receive(0); amount = new BigInteger(result); con.Send(0, new byte[1]); result = con.Receive(0); id = new BigInteger(result); con.Send(0, new byte[1]); var no_series = BitConverter.ToInt32(con.Receive(0), 0); con.Send(0, new byte[1]); for (int i = 0; i < no_series; i++) { result = con.Receive(0); con.Send(0, new byte[1]); s_series.Add(new BigInteger(result)); result = con.Receive(0); con.Send(0, new byte[1]); t_series.Add(new BigInteger(result)); result = con.Receive(0); con.Send(0, new byte[1]); u_hashes.Add(new BigInteger(result)); result = con.Receive(0); con.Send(0, new byte[1]); w_hashes.Add(new BigInteger(result)); } Console.WriteLine("\t[debug]: Banknote received."); } }
public void EstablishConnectionWithBank() { bank_connection = new Connection(); try { bank_connection.socket.Connect(bank_connection.ipEndPoint); Console.WriteLine("[info]: Connection accepted."); } catch (SocketException e) { Console.WriteLine("[fail]: Something went wrong!\n" + e.Message); } }