使用socket网络编有界面的程序时,应该在怎么定义一个socket,是在窗口函数还是winmain中定义。还有在哪里定义sockaddr_in这个数据结构,以及其参数,是在窗口过程中么???求哪位大神给一段简单的界面socket代码

解决方案 »

  1.   

    没有界面的socket 弄明白了没? 图形化界面的程序编过没?
    没学会走,就想跑
      

  2.   

    http://wenku.baidu.com/view/06fb16bec77da26925c5b03b.html第7,8页,有直接的代码,使用的wsaselect模型。 你可以抄过去自己研究研究
      

  3.   

    socket本来就没有界面的,呵呵,只是数据传输的一种方式。等我吃完饭,我给你详细说。
      

  4.   

    哪里定义都没关系,只要保证程序能运行的到,并且调用时是有效的。至于代码,网上socket代码实在是太多了。你可以根据自己需求挑选下,同步异步的,使用模型的(诸如select模型的)等等。
    还有就是API的不同的。。Linux纯C接口的,还有Windows的WSA的等等。
      

  5.   

    一般要用到多线程,即界面一个线程,然后网络通信一个线程,如果是服务端,还要为每个客户端创建一个线程进行通信。网络部分需要和界面部分相互交换数据的时候,使用SendMessage就不用考虑同步问题。
      

  6.   

    看看这里的socket例子代码吧:
    http://download.csdn.net/detail/geoff08zhang/4571358
      

  7.   

    这个帖子不就是了
    http://bbs.csdn.net/topics/390257815
      

  8.   


    要大胆尝试,多看看msdn吧
    This function creates a socket that is bound to a specific service provider.Note   This function is actually a Winsock function. However, the information that is presented in it is specific to Bluetooth.
    SOCKET socket(
      int af,
      int type,
      int protocol
    );
    Parameters
    af 
    [in] Address family specification. To create a Bluetooth socket, use: af = AF_BTH 
    type 
    [in] Type specification for the new socket. To create a Bluetooth socket, use: 
    type = SOCK_STREAM protocol 
    [in] Protocol to be used with the socket that is specific to the indicated address family. To create a Bluetooth socket, use: 
    protocol = BTHPROTO_RFCOMM Return Values
    If no error occurs, this function returns a descriptor referencing the new socket. If an error occurs, a value of INVALID_SOCKET is returned, and a specific error code can be retrieved by calling WSAGetLastError. Res
    The following example code shows how to use socket to create a Bluetooth socket.SOCKET s = socket (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
    For more information about the socket function, see socket (Windows Sockets) in the Winsock reference.
      

  9.   

    求哪位大神给一段简单的界面socket代码   随便百度google下 代码都有了吧?