1 unstable release

0.1.9 Aug 13, 2023
0.1.8 Aug 13, 2023
0.1.6 Jul 27, 2023

#1788 in Network programming

Download history 19/week @ 2024-02-19 10/week @ 2024-02-26 10/week @ 2024-03-11 169/week @ 2024-04-01

179 downloads per month
Used in goxoy-socket-server

MIT license

11KB
207 lines

Goxoy Socket Client

Soket İstemcisi için RUST tabanlı kütüphane.

Kullanım / Örnekler

// önce nesneyi oluşturup, sonrasında ayarları tanımlayabilirsiniz.
let mut client_obj = SocketClient::new());

// bağlantı esnasında ayarları tanımlayabilirsiniz.
client_obj.connect_with_config(AddressParser {
    ip_address: "127.0.0.1".to_string(),
    port_no: 1234,
    protocol_type: ProtocolType::TCP,
    ip_version: IPAddressVersion::IpV4,
});


// ayarlar ile nesneyi oluşturmak için
let mut client_obj = SocketClient::new_with_config(AddressParser {
    ip_address: "127.0.0.1".to_string(),
    port_no: 1234,
    protocol_type: ProtocolType::TCP,
    ip_version: IPAddressVersion::IpV4,
});

//mesaj gelince devreye girecek fonksiyon
client_obj.on_received( |data| {
    println!("Data Received : {}", String::from_utf8(data.clone()).unwrap());
});

// sunucu bağlantı durumları tetiklendiğinde
client_obj.on_connection_status( |connection_status| {
    match connection_status {
        SocketConnectionStatus::Connected => {
            println!("Socket Connected");
        },
        SocketConnectionStatus::Disconnected => {
            println!("Socket Disconnected");
        },
    }
});

// hata oluştuğunda devreye girecek fonksiyon
client_obj.on_error(|error_type| {
    match error_type {
        SocketClientErrorType::Connection => {
            println!("Connection Error");
        },
        SocketClientErrorType::Communication => {
            println!("Communication Error");
        },
    }
});

// ayarları nesneyi oluştururken belirttiyseniz, doğrudan bağlantı kurabilirsiniz.
client_obj.connect();

// mesaj göndermek için
let result_obj = client_obj.send("test_msg".as_bytes().to_vec());
if result_obj==true {
    println!("Message Sended");
}else{
    println!("Message Sending Error");
}

Lisans

MIT

Dependencies

~1MB