public Message SendMesssage(Message message) { // Connect to a remote device. try { // Establish the remote endpoint for the socket. // The name of the // remote device is "host.contoso.com". var ipAddress = IPAddress.Parse(Address ?? address); IPEndPoint remoteEP = new IPEndPoint(ipAddress, port); // Create a TCP/IP socket. Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect to the remote endpoint. client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client); connectDone.WaitOne(); // Send test data to the remote device. string requestString = message.GetAsString(); Send(client, requestString); sendDone.WaitOne(); // Receive the response from the remote device. Receive(client); receiveDone.WaitOne(); // Write the response to the console. Console.WriteLine("Response received : {0}", response); // Release the socket. client.Shutdown(SocketShutdown.Both); client.Close(); return new Message(response); } catch (Exception e) { Console.WriteLine(e.ToString()); return new Message(); } }
public void Refresh(Message message) { }
public Message MakeTurn(Client client) { Message message = new Message(); message.AddProperty("sessionId", Client.Instance.SessionId.ToString()); message.AddProperty("buildFabricCount", Client.Instance.BuyFCount.ToString()); message.AddProperty("automateFabricCount", Client.Instance.UpFCount.ToString()); message.AddProperty("buildAFabricCount", Client.Instance.BuyAFCount.ToString()); message.AddProperty("buildAFabricCount", Client.Instance.BuyAFCount.ToString()); message.AddProperty("loanCount", Client.Instance.NewLoan.ToString()); message.AddProperty("produceESM", "{\"count\":" + Client.Instance.ProduceESMCount + ",\"price\":" + Client.Instance.ProduceESMCost + "}"); message.AddProperty("esm", "{\"count\":" + Client.Instance.BuyESMCount + ",\"price\":" + Client.Instance.BuyESMCost + "}"); message.AddProperty("egp", "{\"count\":" + Client.Instance.SellEGPCount + ",\"price\":" + Client.Instance.SellEGPCost + "}"); return SendMesssage(message); }
public Message GetBankState() { Message message = new Message(); message.AddProperty("type", "state"); Message resoponseMessage = SendMesssage(message); return resoponseMessage; }
public int Connect(Client client) { Message message = new Message(); message.AddProperty("type", "connect"); message.AddProperty("name", client.Name); Message resoponseMessage = SendMesssage(message); string sessionId = resoponseMessage.GetProperty("sessionId"); if (sessionId == null) throw new NotEnouthSpaceException(); return int.Parse(sessionId.Substring(1, sessionId.Length - 2)); }
public void StartNewgame() { Message request = new Message(); request.AddProperty("type", "create"); Message response = SendMesssage(request); }