php 簡單訊息推送 含原始碼

2021-08-02 18:30:43 字數 2242 閱讀 3835

入口** index.html

反ajax推送title>

.send

.require

.content_box

style>

src="">

script>

head>

class="content_box"

id="content_box_title"

style="border: none;">訊息框div>

class="content_box"

id="content_box">

div>

style="width: 450px;margin: 0 auto;">

id="username"

style="font-size: 20px;">

value="1"

selected="selected">1option>

value="2">2option>

select>

type="text"

style="font-size: 20px;"

value=""

id="send_text">

id="btn_send"

style="font-size: 20px;">傳送button>

id="btn_link"

style="font-size: 20px">連線button>

div>

class="error_tip"

id="error_tip"

style="color: red;">

div>

$(function()else

});//按回車鍵傳送訊息

$('#send_text').on('keyup',function(e)

});//建立通訊鏈結

$('#btn_link').click(function());

});//建立通訊連線函式

function

connect(),

url:'ajaxpush.php',

type:'get',

timeout:0,

datatype:'json',

success:function(data)

});}

//傳送訊息函式

function

send(massege),function(data)else

});}

script>

body>

html>

ajax處理輸入 write.php

<?php

/** * created by txm.

* time: 2015/4/18 13:13

* function:

*/$filename = dirname(__file__).'/data.txt';

$isread_file = dirname(__file__).'/isread.txt';

$user = dirname(__file__).'/user.txt';

//寫入訊息,訊息未讀,誰傳送的訊息

file_put_contents($filename,$_get['msg']);

file_put_contents($isread_file,'0');

file_put_contents($user,$_get['user']);

echo json_encode(array('sf'=>true));

長輪詢推送 ajaxpush.php

<?php

/** * created by txm.

* time: 2015/4/18 13:12

* function:

*/$filename = dirname(__file__).'/data.txt';

$isread_file = dirname(__file__).'/isread.txt';

$userfile = dirname(__file__).'/user.txt';

$get_user = $_get['user'] == '1'?'2':'1';

$msg='';

while(1)

sleep(1);

}echo json_encode(array('msg'=>$msg));

編譯原始碼 含CMake

習慣了使用命令列,下面介紹windows下配置命令列編譯c 和c 不用使用工具建立工程,解決方案這麼笨重 一 windows下使用cl.exe編譯c 1.新增path c program files x86 microsoft visual studio 2017 enterprise vc too...

php 訊息實時推送(反ajax推送)

入口檔案index.html 反ajax推送title send require content box style src script head class content box id content box title style border none 訊息框div class conte...

簡單的socket例項及原理(含原始碼)

所謂socket通常也稱作 套接字 用於描述ip位址bai和埠,是乙個通訊鏈的控制代碼。應用程式通常通過 套接字 向網路發出請求或者應答網路請求。socket分為服務端及客戶端,這裡我們用serversocket及clientsocket分別表示 伺服器監聽 伺服器端socket並不主動指定的客戶端...