文件名称:socket
- 所属分类:
- Internet/网络编程
- 资源属性:
- [C/C++] [源码]
- 上传时间:
- 2012-11-26
- 文件大小:
- 2kb
- 下载次数:
- 0次
- 提 供 者:
- 闛*
- 相关连接:
- 无
- 下载说明:
- 别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容均来自于网络,请自行研究使用
tcp udp 网络编程源码 //创建套接字
sHost = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
if(INVALID_SOCKET == sHost)
{
printf("socket failed!\n")
WSACleanup() //释放套接字资源
return -1
}
//设置服务器地址
servAddr.sin_family =AF_INET
servAddr.sin_addr.s_addr = inet_addr("127.0.0.1")
servAddr.sin_port = htons((short)4999)
int nServAddlen = sizeof(servAddr)
//连接服务器
retVal=connect(sHost,(LPSOCKADDR)&servAddr, sizeof(servAddr))
if(SOCKET_ERROR == retVal)
{
printf("connect failed!\n")
closesocket(sHost) //关闭套接字
WSACleanup() //释放套接字资源
return -1
}
//向服务器发送数据
ZeroMemory(buf, BUF_SZIE)
strcpy(buf, "MyTCP")
retVal = send(sHost, buf, strlen(buf), 0)
if (SOCKET_ERROR == retVal)
{
printf("send failed!\n")
closesocket(sHost) //关闭套接字
WSACleanup() //释放套接字资源
return -1 -tcp udp network programming source code// create a socket sHost = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP) if (INVALID_SOCKET == sHost) (printf ( " socket failed! \ n" ) WSACleanup () // release socket Word of resources return-1 )// set the server address servAddr.sin_family = AF_INET servAddr.sin_addr.s_addr = inet_addr ( " 127.0.0.1" ) servAddr.sin_port = htons ((short) 4999) int nServAddlen = sizeof ( servAddr) // connect to the server retVal = connect (sHost, (LPSOCKADDR) & servAddr, sizeof (servAddr)) if (SOCKET_ERROR == retVal) (printf ( " connect failed! \ n" ) closesocket (sHost) // Close socket WSACleanup () // release the socket resources return-1 )// to the server sending data ZeroMemory (buf, BUF_SZIE) strcpy (buf, " MyTCP" ) retVal = send (sHost, buf, strlen (buf), 0) if (SOCKET_ERROR == retVal) (printf ( " send failed! \ n" ) closesocket (sHost) // close the socket WSACleanup () // release socket resources to return
sHost = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
if(INVALID_SOCKET == sHost)
{
printf("socket failed!\n")
WSACleanup() //释放套接字资源
return -1
}
//设置服务器地址
servAddr.sin_family =AF_INET
servAddr.sin_addr.s_addr = inet_addr("127.0.0.1")
servAddr.sin_port = htons((short)4999)
int nServAddlen = sizeof(servAddr)
//连接服务器
retVal=connect(sHost,(LPSOCKADDR)&servAddr, sizeof(servAddr))
if(SOCKET_ERROR == retVal)
{
printf("connect failed!\n")
closesocket(sHost) //关闭套接字
WSACleanup() //释放套接字资源
return -1
}
//向服务器发送数据
ZeroMemory(buf, BUF_SZIE)
strcpy(buf, "MyTCP")
retVal = send(sHost, buf, strlen(buf), 0)
if (SOCKET_ERROR == retVal)
{
printf("send failed!\n")
closesocket(sHost) //关闭套接字
WSACleanup() //释放套接字资源
return -1 -tcp udp network programming source code// create a socket sHost = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP) if (INVALID_SOCKET == sHost) (printf ( " socket failed! \ n" ) WSACleanup () // release socket Word of resources return-1 )// set the server address servAddr.sin_family = AF_INET servAddr.sin_addr.s_addr = inet_addr ( " 127.0.0.1" ) servAddr.sin_port = htons ((short) 4999) int nServAddlen = sizeof ( servAddr) // connect to the server retVal = connect (sHost, (LPSOCKADDR) & servAddr, sizeof (servAddr)) if (SOCKET_ERROR == retVal) (printf ( " connect failed! \ n" ) closesocket (sHost) // Close socket WSACleanup () // release the socket resources return-1 )// to the server sending data ZeroMemory (buf, BUF_SZIE) strcpy (buf, " MyTCP" ) retVal = send (sHost, buf, strlen (buf), 0) if (SOCKET_ERROR == retVal) (printf ( " send failed! \ n" ) closesocket (sHost) // close the socket WSACleanup () // release socket resources to return
(系统自动生成,下载前可以参看下载内容)
下载文件列表
网路编程\Client.c
........\Desk_top_.ini
........\Server.c
网路编程
........\Desk_top_.ini
........\Server.c
网路编程