static void Main(string[] args) { var client = new XClient(null); client.Init("127.0.0.1", 9090); Console.ReadKey(); }
private void HandlePacket(XClient client, byte[] data) { try { client.conn.Send(data); } catch { return; } }
public void Send(XClient client, byte[] data) { try { if (client.s.Connected) { client.s.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), client.s); } } catch { return; } }
public ClientConnector(XClient _client, IPEndPoint _ip) { this.client = _client; this.ip = _ip; try { connector = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); connector.BeginConnect(ip, new AsyncCallback(ConnectCallback), connector); } catch { return; } }
public async Task PassingSeach() { var token = await GetToken(); var request = new HttpRequestMessage(HttpMethod.Get, "/api/user"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); var response = await XClient.SendAsync(request, HttpCompletionOption.ResponseContentRead); var content = await response.Content.ReadAsStringAsync(); var payload = content.JsonToObj <ApiResultOk>(); Assert.Equal("Ok", payload.Message); }
private void ReceiveCallback(IAsyncResult ar) { XClient client = (XClient)ar.AsyncState; try { if (client == null) { return; } if (client.s == null) { return; } if (!client.s.Connected) { return; } int bytes_receive = client.s.EndReceive(ar); if (bytes_receive > 0) { byte[] data = new byte[bytes_receive]; Array.Copy(client.buff, data, bytes_receive); HandlePacket(client, data); client.buff = new byte[XClient.BufferSize]; client.s.BeginReceive(client.buff, 0, XClient.BufferSize, SocketFlags.None, new AsyncCallback(ReceiveCallback), client); } else { // disconnect client DisconnectClient(client.id); return; } } catch { // disconnect client; error operand DisconnectClient(client.id); return; } }
public async Task FailingToken() { var dto = new LoginUserDto { Email = "*****@*****.**", Password = "******" }; var request = new HttpRequestMessage(HttpMethod.Post, "/oauth/connect-token") { Content = dto.ObjToHttpContent() }; var response = await XClient.SendAsync(request, HttpCompletionOption.ResponseContentRead); var content = await response.Content.ReadAsStringAsync(); var payload = content.JsonToObj <ApiResultOk>(); Assert.NotEqual("Ok", payload.Message); }
public async Task FailingRegister() { var dto = new RegisterUserDto { UserName = "******", Email = "*****@*****.**", Password = "******", Role = "User" }; var request = new HttpRequestMessage(HttpMethod.Post, "/api/account/register-user") { Content = dto.ObjToHttpContent() }; var response = await XClient.SendAsync(request, HttpCompletionOption.ResponseContentRead); var content = await response.Content.ReadAsStringAsync(); var payload = content.JsonToObj <ApiResultOk>(); Assert.NotEqual("Ok", payload.Message); }
public Message(XClient client) { this.Client = client; }
public HeartBeatHandler(XClient client) { this.client = client; }
public XPlayer(XClient client) { Client = client; }
public XAudioLibrary(XClient client) { _Client = client; }
public AS_REQ(XClient client) : base(client) { }
public XPicturePlayer(XClient client) : base(client) { }
private void AcceptCallback(IAsyncResult ar) { if (!Info.Running) { return; } Socket s = (Socket)ar.AsyncState; try { Socket s_client = s.EndAccept(ar); int client_id = s_client.GetHashCode(); Clients.Add(new XClient(s_client, client_id)); XClient client = GetClientByID(client_id); if (client == null) { return; } //MessageBox.Show("Client conectado: " + client_id.ToString()); string ip_redirect = TBRedirectIP.Text; Uri uriResult; IPAddress ip; bool result = Uri.TryCreate(ip_redirect, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (result) { ip = Dns.GetHostAddresses(uriResult.Host)[0]; } else { IPAddress.TryParse(ip_redirect, out ip); } IPEndPoint direct = new IPEndPoint(ip, int.Parse(TBRedirectPort.Text)); ClientConnector conn = new ClientConnector(client, direct); client.conn = conn; Thread.Sleep(600); this.Invoke(new Action(() => { string s_ip = ((IPEndPoint)(client.s.RemoteEndPoint)).Address.ToString(); LBClients.Items.Add("[" + client.id + "] " + s_ip + " -> " + client.conn.ip.Address.ToString()); })); client.s.BeginReceive(client.buff, 0, XClient.BufferSize, SocketFlags.None, new AsyncCallback(ReceiveCallback), client); } catch (Exception e) { MessageBox.Show(e.ToString()); return; } finally { if (Info.Running) { s.BeginAccept(new AsyncCallback(AcceptCallback), s); } } }
public XVideoPlayer(XClient client) : base(client) { }
public XAudioPlayer(XClient client) : base(client) { }
public XVideoLibrary(XClient client) { _Client = client; }
public XPlaylist(XClient client) { Client = client; }