void OnMessageReceived(byte[] receivedData) { HoldemState receivedState = new HoldemState(receivedData); Log += string.Format("{0}\n", receivedState); connection.Send(new AutoplayerInstruction(AutoplayerAction.Fold, -1, 0)); }
public void SendCalibrate(TCPConnection connection) { List <byte> data = new List <byte>(); data.WriteString("calibrate"); connection.Send(data); }
public void SendLogsQuery(TCPConnection connection) { List <byte> data = new List <byte>(); data.WriteString("logs-query"); connection.Send(data); }
public void Send(Serializable Message, TCPConnection Connection) { SerializationOutputStream stream = new SerializationOutputStream(new MemoryStream()); Serialize(Message, stream); Connection.Send(stream); }
public void SendGuideUnlock(TCPConnection connection) { List <byte> data = new List <byte>(); data.WriteString("guide-unlock"); connection.Send(data); }
public void SendGuideUnpair(TCPConnection connection) { List <byte> data = new List <byte>(); data.WriteString("guide-unpair"); OnReceivePairConfirm(connection, "0", connection.lockedId); //simulate receiving an immediate response when unpairing. connection.Send(data); }
public void Execute(object parameter) { Message outgoingMessage = new MessageCommand(MsgType.Command, SubType.JoinRoom, ((string)parameter), Parent.Username, ""); TCPConnection.Send(outgoingMessage); outgoingMessage = new MessageCommand(MsgType.Command, SubType.Userlist, ((string)parameter), Parent.Username, ""); TCPConnection.Send(outgoingMessage); }
static void Main(string[] args) { Console.WriteLine("Test TCPConnetion"); Console.WriteLine("------------------------------------"); Console.WriteLine("Who are you?"); string tempRole = Console.ReadLine(); TCPRole role; if (tempRole.ToLower().Contains("server")) { role = TCPRole.Server; } else { role = TCPRole.Client; } tcpConnection = new TCPConnection(role, IPAddress.Parse("129.69.220.10"), 3001); if (role == TCPRole.Server) { Random r = new Random(2000); while (true) { Console.WriteLine("Send data: "); string data = Console.ReadLine(); if (data == "go") { MISD.Client.Model.LayoutChangeCommand l = new MISD.Client.Model.LayoutChangeCommand(r.Next(), new MonitoredSystemState(r.Next())); tcpConnection.Send(l); } else { tcpConnection.Send(data); } } } else { tcpConnection.newDataReceived += tcpConnection_newDataReceived; } }
public void SendHasVideo(TCPConnection connection, string videoName) { List <byte> data = new List <byte>(); data.WriteString("has-video"); data.WriteString(videoName); //if(TCPHost.Instance) // TCPHost.Instance.BroadcastToPairedDevices(data); connection.Send(data); Haze.Logger.Log("Requesting devices for video " + videoName + ".."); }
public void SendAutocalibration(TCPConnection connection, byte command) { List <byte> data = new List <byte>(); data.WriteString("autocalibration"); data.WriteByte(command); if (connection != null && connection.active) { connection.Send(data); } }
/** * When the response of the hub is successful, we terminate the handshake * */ private void OnReply() { try { HttpHeader h = new HttpHeader(); h[HttpHeader.PROTOCOL_KEY] = "GNUTELLA/0.6 200 OK"; h[HttpHeader.CONTENT_TYPE_KEY] = HttpHeader.CONTENT_TYPE_G2_VALUE; h[HttpHeader.IS_HUB_KEY] = "False"; //h[HttpHeader.IS_ULTRA_PEER_KEY] = "False"; // /** TODO check if encoding is present **/ setEncoding(h); byte[] msg = System.Text.Encoding.ASCII.GetBytes(h.ToString()); bool byte_sent = tcp.Send(new ByteBuffer(msg)); } catch (ArgumentNullException ane) { throw new ArgumentNullException("GHandshakeOnReply() : {0}", ane.ToString()); } catch (SocketException se) { throw new NetException("GHandshakeOnReply() : " + se.ToString()); } catch (Exception e) { G2Log.Write("GHandshake ERROR OnReply() : " + e.ToString()); } }
public void SendGuidePair(TCPConnection connection) { if (OnlyAcceptOneConnection && TCPHost.Instance.NumberOfPairedDevices > 0) { return; } List <byte> data = new List <byte>(); data.WriteString("guide-pair"); connection.Send(data); }
public void SendLogs() { if (currentlyPaired != null) { List <byte> data = new List <byte>(); data.WriteString("logs"); data.WriteString(logs); logs = ""; currentlyPaired.Send(data); } }
public void SendAutopair(TCPConnection connection) { if (currentlyPaired == null && TCPClient.Instance && connection.uniqueId == TCPClient.Instance.LockedId) { List <byte> data = new List <byte>(); data.WriteString("autopair"); Haze.Logger.Log("Sending autopair request"); connection.Send(data); } else { Haze.Logger.LogWarning("Not allowed to send autopair to " + connection + "..."); } }
/// <summary> /// Sends a LayoutChangeCommand to the Powerwalls if this COmputer isOperatorPC. /// </summary> /// <param name="layoutChangeCommand">A Layout change command</param> private void SendLayoutChanges(LayoutChangeCommand layoutChangeCommand, bool sendFullLayout = false) { if (ConfigClass.IsOperator && tcpConnection != null) { if (sendFullLayout) { var l = new LayoutChangeCommand(this.CurrentLayout); tcpConnection.Send(l); counterLayoutChanges = 0; } else { counterLayoutChanges++; tcpConnection.Send(layoutChangeCommand); if (counterLayoutChanges > 10) { var l = new LayoutChangeCommand(this.CurrentLayout); tcpConnection.Send(l); counterLayoutChanges = 0; } } } }
private bool SendHttpRequest(TCPConnection con) { HttpHeader header = new HttpHeader(); string request = @"GET / HTTP/1.1" + HttpHeader.nl; request += HttpHeader.ACCEPT_KEY + ": " + @"text/html, " + HttpHeader.G2ACCEPT_DEFAULT_VALUE + HttpHeader.nl; request += HttpHeader.USER_AGENT_KEY + ": " + Settings.USER_AGENT + HttpHeader.nl; request += HttpHeader.ACCEPT_ENCODING_KEY + @": identity" + HttpHeader.nl; request += @"Connection: close" + HttpHeader.nl; request += @"Host: " + Peer.Address.ToString() + ":" + Peer.Port; request += HttpHeader.nl + HttpHeader.nl; bool succ = con.Send(new ByteBuffer(BinaryUtils.getSimpleBytesFromString(request))); return(succ); }
private async void Communicate(TCPConnection connection) { while (connection.active) { List <byte> data = await connection.Receive(); if (data.Count > 0) { string channel = data.ReadString(); if (channel == "disconnection") { connection.active = false; } else { //received a message from the host! onMessageReception.Invoke(connection, channel, data); } } else { Haze.Logger.LogWarning("Received data with length == 0 from connection " + connection); connection.active = false; } } //Attempt to send a "disconnection" message before closing { List <byte> data = new List <byte>(); data.WriteString("disconnection"); try { await connection.Send(data); } catch (Exception e) { //nevermind. } } onConnectionEnd.Invoke(connection); users.Remove(connection); if (!connection.UDP) { connection.client.Close(); } }
public async Task <bool> ConnectToHost(IPEndPoint endpoint, string uniqueId, IPEndPoint udpEndpoint) { TCPConnection connection = new TCPConnection(); connection.uniqueId = uniqueId; connection.deviceType = TCPConnection.DeviceType.GUIDE; connection.client = new TcpClient(); connection.client.NoDelay = true; connection.sourceEndpoint = endpoint; IPAddress ipv4 = endpoint.Address; if (ipv4.AddressFamily != AddressFamily.InterNetwork) { ipv4 = ipv4.MapToIPv4(); } Haze.Logger.Log("IPv4: " + ipv4); bool tcp = false; try { CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(10000); //Cancel after 10 seconds TaskCompletionSource <bool> cancellationCompletionSource = new TaskCompletionSource <bool>(); var connectAsync = connection.client.Client.ConnectAsync(ipv4, endpoint.Port); using (cts.Token.Register(() => cancellationCompletionSource.TrySetResult(true))) { if (connectAsync != await Task.WhenAny(connectAsync, cancellationCompletionSource.Task)) { throw new OperationCanceledException(cts.Token); } } Haze.Logger.Log("Connected through TCP. Sending identification message..."); tcp = true; } catch (SocketException se) { Haze.Logger.LogError("[TCPClient] Socket Exception (" + se.ErrorCode + "), cannot connect to host: " + se.ToString(), this); } catch (Exception e) { Haze.Logger.LogError("[TCPClient] Error, cannot connect to host: " + e.ToString(), this); } if (!tcp) { if (!allowUdp) { return(false); //nope, not allowed... } //Something went wrong and TCP was unavailable. Fallback to UDP Haze.Logger.Log("Attempting to fall back to UDP with " + udpEndpoint); connection.client = null; connection.udpEndpoint = udpEndpoint; } try { List <byte> data = new List <byte>(); data.WriteString("identification"); data.WriteByte((byte)deviceType); data.WriteString(SystemInfo.deviceUniqueIdentifier); data.WriteString(LockedId); data.WriteString(XRDevice.model); await connection.Send(data); hosts.Add(connection); onNewConnection.Invoke(connection); Communicate(connection); return(true); } catch (SocketException se) { Haze.Logger.LogError("[TCPClient] Socket Exception (" + se.ErrorCode + "), cannot send identification message to host: " + se.ToString(), this); } catch (Exception e) { Haze.Logger.LogError("[TCPClient] Error, cannot send identification message to host: " + e.ToString(), this); } UDPListener.Instance.RemoveEncounteredIP(endpoint); return(false); }