English 中文(简体)
• 如何打赢客户
原标题:how to tag clients with winsock

我有一个简单的服务器客户胜诉方案。 而且,大麻知道并增加了两条东西。

I tag/ID客户如何?

并且能够把所有客户的数据寄给后?

这是我目前掌握的纽带。 “客户”是我试图对客户进行tag击/id,但可能不正确的东西。

for(;;)
{
 if(Connect = accept(Listen, (SOCKADDR*)&Server, &size))
  {
    std::cout<<"
Connection was reached";    
    a = a +1;
    client_id[a] = accept(Listen, (SOCKADDR*)&Server, &size) ???
  }
}

利用C/C++和窗口。

希望有人能帮助我解决这一问题。

感谢。

问题回答

与服务器连接的每个客户都有自己的识别标志SOCKET。 不使用你的习俗标识。 此外,还使用动态阵列——“和”; st:为保持客户身份而挖掘或绘制地图。

同样,你会重复接受,你会失去二次联系。

std::vector< SOCKET > clients;
...
for(;;)
{
 if(Connect = accept(Listen, (SOCKADDR*)&Server, &size))
  {
    std::cout<<"
Connection was reached";    
    clients.push_back( Connect )
  }
}

如果是地图,你有这样的东西。

std::map< SOCKET, YouClientClass > clients;
...
for(;;)
{
 if(Connect = accept(Listen, (SOCKADDR*)&Server, &size))
  {
    std::cout<<"
Connection was reached";    
    clients.insert( std::make_pair( Connect, YourClientClass(Connect))); 
  }
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签