🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.unix.development.network
Article #9

����һ����ֵ�����

#9
From: һ�쵽����Ӿ����
Date: Fri, 07 Nov 2003 02:05
37 lines
2312 bytes
�Ҹտ�ʼѧwinsock��̣�������д�������TCP server,ִ�г������5150�˿ڼ��������client���Ӿ���ʾA new connection has been made Ȼ���˳�
�����ҷ������ int Port=5150��һ������WSADATA wsaData֮ǰ������ִ�к�û��client���Ӿ���ʾA new connection has been made Ȼ���˳�
why?
�����ָ�㣡
#include <winsock2.h>
#include <iostream>
using namespace std;
int main()
{
   WSADATA              wsaData;
   SOCKET               ListeningSocket;
   SOCKADDR_IN          ServerAddr;
   SOCKADDR_IN          ClientAddr;
   int                  Port = 5150;
   WSAStartup(MAKEWORD(2,2), &wsaData);
 
   ListeningSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
          
   ServerAddr.sin_family = AF_INET;
   ServerAddr.sin_port = htons(Port);    
   ServerAddr.sin_addr.s_addr = htonl(INADDR_ANY);
          
   bind(ListeningSocket, (SOCKADDR *)&ServerAddr,sizeof(ServerAddr));
   listen(ListeningSocket, 5); 
   SOCKET NewConnection;
   int ClientAddrLen;
   NewConnection = accept(ListeningSocket, (SOCKADDR *)&ClientAddr,&ClientAddr
Len);
   cout<<"A new connection has been made\n";
   closesocket(NewConnection);
   closesocket(ListeningSocket);
   WSACleanup();
}

--

�� ��Դ:��BBS ˮľ�廪վ smth.org��[FROM: 202.118.224.2]
Technical Details
Message-ID: <000000$W9K@smth.org>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed.news2me.com!snoopy.risq.qc.ca!nf3.bellglobal.com!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!SMTH

Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB
X-Google-Thread: 109ae0,9533a1a0034c01c,start
X-Google-Attributes: gid109ae0,public
X-Google-Thread: 1003d3,9533a1a0034c01c,start
X-Google-Attributes: gid1003d3,public
X-Google-ArrivalTime: 2003-11-06 18:10:03 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed.news2me.com!snoopy.risq.qc.ca!nf3.bellglobal.com!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!SMTH
From: godkiller@smth.org (һ�쵽����Ӿ����)
Newsgroups: cn.bbs.comp.unix.development.network
Subject: ����һ����ֵ�����
Date: 07 Nov 2003 02:05:53 GMT
Organization: BBS ˮľ�廪վ
Message-ID: <000000$W9K@smth.org>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: NetPRG/J/M.1068170505.q0
Lines: 37