Home Backend Development PHP Tutorial C与php socket通讯

C与php socket通讯

Jun 13, 2016 am 10:39 AM
buffer include lt

C与php socket通信

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define PORT 80

#define SERVER_IP "192.168.1.21"

?

int main(int argc,char *argv[])

{

int ii,i,serverSocket;

struct sockaddr_in clientAddr;

char buffer[4096];

serverSocket =socket(AF_INET,SOCK_STREAM,0);

if(serverSocket==-1)

? {

?printf("Invalid socket\n");

?exit(1);

? }

bzero(&clientAddr,sizeof(clientAddr));?

clientAddr.sin_family=AF_INET;

clientAddr.sin_port=htons(PORT);

clientAddr.sin_addr.s_addr=inet_addr(SERVER_IP);

if(connect(serverSocket,&clientAddr,sizeof(clientAddr))

{

perror("connect");

exit(1);

}

strcpy(buffer,"GET / HTTP/1.1\nHost:192.168.1.21\n\n");

printf("\n%s\n",buffer);

if(send(serverSocket,buffer,sizeof(buffer),0)

{

perror("send error");

exit(1);

}

ii=(int)recv(serverSocket,buffer,sizeof(buffer),0);

printf("\nrev=%d length\n",ii);

for(i=0;i

{

printf("%c",buffer[i]);

}

return 1;

}


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between php include and include_once What is the difference between php include and include_once Mar 22, 2023 am 10:38 AM

When we write web pages using PHP, sometimes we need to include code from other PHP files in the current PHP file. At this time, you can use the include or include_once function to implement file inclusion. So, what is the difference between include and include_once?

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

What is the concept of Buffer in java What is the concept of Buffer in java Apr 28, 2023 pm 05:13 PM

1. Concept of using JavaNIOBuffers to interact with NIOChannel. Read data from Channel to buffers, and write data from Buffer to Channels; the three properties of Buffer must be controlled, namely capacity, position-location, and limit. 2. Instance publicstaticvoidmain(String[]args){//Generate a buffer with a length of 10IntBufferintBuffer=IntBuffer.allocate(10);for(inti=0;i

Microsoft is rolling out Windows 11 23H2 build to the release preview channel with Copilot Microsoft is rolling out Windows 11 23H2 build to the release preview channel with Copilot Sep 28, 2023 pm 07:17 PM

Everyone is looking forward to today's Windows 1123H2 release. In fact, Microsoft has just launched updates to the release preview, which is the closest channel before the official release stage. Known as Build 22631, Microsoft said they are rolling out the new rebranded chat app, phone link, and play together widgets that have been tested on other internal channels over the past few months. "This new update will have the same servicing branch and codebase as Windows 11 version 22H2 and will be cumulative with all newly announced features, including Copilot in Windows (preview)," Microsoft promises. Redmond officials further

What are the methods and usage scenarios of using Buffer for IO stream operations in Java? What are the methods and usage scenarios of using Buffer for IO stream operations in Java? May 07, 2023 am 09:37 AM

Using Buffer for I/O stream operations In addition to NIO, there are two basic methods for using Java to perform I/O operations: using methods based on InputStream and OutputStream; (byte streams) using Writer and Reader. (Character stream) No matter which method is used for file I/O, if buffering can be used reasonably, I/O performance can be effectively improved.

How to include one php.ini file within another php.ini file? How to include one php.ini file within another php.ini file? Sep 02, 2023 pm 03:45 PM

Unable to include .ini file in main php,ini file. In contrast, when compiling PHP, the line --with-config-file-scan-dir=PATH​​​​​&a

PHP file:// PHP file:// Aug 20, 2023 pm 06:13 PM

Introduction In PHP, various URL style protocols can be used in conjunction with file system functions, with the help of corresponding built-in wrappers. Custom wrappers can also be defined using the stream_wrapper_register() function. The default wrapper in PHP is file://, which represents the local file system. If no other protocol is explicitly used, the PHP parser will treat it as a filesystem wrapper. The file name parameters passed to the file system functions fopen(), file_get_contents(), etc. use the file:// protocol by default. When the file name does not begin with a forward slash, a backslash, or the driver in Windows

请教怎么修改url某一参数的参数值呢?是要拆开了再拼回去吗 请教怎么修改url某一参数的参数值呢?是要拆开了再拼回去吗 Jun 13, 2016 am 10:24 AM

请问如何修改url某一参数的参数值呢?是要拆开了再拼回去吗?那么请问如何修改url某一参数的参数值呢?是要拆开了再拼回去吗?http://127.0.0.1/myo/newuser.php?mod=search&type=fastone比如现在我要修改mod=new要怎么做呢?------解决方案--------------------发送了请求

See all articles