Skip to content

Commit 52e99b7

Browse files
authored
Merge pull request #107 from Magic07/ipv6
Support IPv6 literal address.
2 parents f62e777 + e666fa0 commit 52e99b7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/internal/sio_client_impl.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,18 @@ namespace sio
205205
#else
206206
ss<<"ws://";
207207
#endif
208-
if (m_sid.size()==0) {
209-
ss<<uo.get_host()<<":"<<uo.get_port()<<"/socket.io/?EIO=4&transport=websocket&t="<<time(NULL)<<queryString;
208+
const std::string host(uo.get_host());
209+
// As per RFC2732, literal IPv6 address should be enclosed in "[" and "]".
210+
if(host.find(':')!=std::string::npos){
211+
ss<<"["<<uo.get_host()<<"]";
212+
} else {
213+
ss<<uo.get_host();
210214
}
211-
else
212-
{
213-
ss<<uo.get_host()<<":"<<uo.get_port()<<"/socket.io/?EIO=4&transport=websocket&sid="<<m_sid<<"&t="<<time(NULL)<<queryString;
215+
ss<<":"<<uo.get_port()<<"/socket.io/?EIO=4&transport=websocket";
216+
if(m_sid.size()>0){
217+
ss<<"&sid="<<m_sid;
214218
}
219+
ss<<"&t="<<time(NULL)<<queryString;
215220
lib::error_code ec;
216221
client_type::connection_ptr con = m_client.get_connection(ss.str(), ec);
217222
if (ec) {

0 commit comments

Comments
 (0)