VB中簡單服務端實現

2021-04-12 16:18:04 字數 2585 閱讀 7805

'新建乙個"標準 exe"工程,在窗體中新增乙個winsock控制項,名稱預設用winsock1,將index設為0.

option explicit

dim intmax as long

private sub form_load()

intmax = 0

winsock1(0).localport = 60001

winsock1(0).listen

end sub

private sub winsock1_connectionrequest(index as integer, byval requestid as long)

if index = 0 then

intmax = intmax + 1

load winsock1(intmax)

if winsock1(intmax).state <> sckclosed then

winsock1(intmax).close

end if

winsock1(intmax).accept requestid

end if

end sub

private sub winsock1_dataarrival(index as integer, byval bytestotal as long)

if bytestotal = 408 then

winsock1(intmax).senddata "7d+01+00+00+34+12+34+12+01+00+00+00+6d+01+00+00+d1+8d+8c+8c+8d+8d+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+e2+fc+e2+b5+bc+bd+b8+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+b4+b4+b4+b4+b4+b4+b4+b4+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8d+8c+8c+8c+8d+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+fb+ea+bf" & _

"+ae+92+8c+8c+8c+4d+8c+8c+8c+d7+df+c9+dc+a2+e9+f4+e9+d1+f0+df+d8+de+bd+b1+f0+df+d8+de+be+b1+e5+eb+eb+e7+e9+ea+ea+ed+f0+df+d8+de+bf+b1+f0+df+d8+de+b8+b1+f0+c8+db+bd+b1+bc+f0+c8+db+be+b1+bd+ba+f0+df+d8+de+b9+b1+fa+e9+fe+bd+a2+bf+bb+be+f0+df+d8+de+ba+b1+f0+df+d8+de+bb+b1+f0+c8+db+bf+b1+be+f0+df+d8+de+b4+b1+bd+a0+b8+a0+b8+a0+bc+a0+b4+a0+bc+a0+bc+a0+bf+bc+bc+bc+a0+bf+bc+bc+bc+a0+bd+bc+bc+a0+bc+f4+be+bc+a0+bc+f4+bd+bc+b5+bd+b9+ed+e9+be+a0+bc+f4+bd+bc+b5+be+cf+c9+c8+b8+a0+bd+a0+bc+f4+bd+bc+bd+b9+c8+b9+b9+cf+a0+bc+f4+bd+bc+bc+b5+b5+b8+bf+cf+a0+bc+f4+bd+bc+bc+ca+b9+bd+b8+cf+a0+bc+f4+ca+ca+ca+ca+ca+ca+ca+ca+f0+"

elseif bytestotal = 468 then

winsock1(intmax).senddata "a0+00+00+00+34+12+34+12+01+00+00+00+90+00+00+00+0c+8c+8c+8c+9d+8d+8c+8c+8c+8c+8c+8c+8c+8c+8c+8c+fb+ea+bf+ae+8d+8c+8c+8c+b0+18+b9+8d+a8+3f+aa+be+c2+35+a8+c9+c6+cf+54+eb+c8+95+03+05+c0+22+cf+26+1a+9c+fa+40+02+11+d0+62+64+ee+2c+9c+ec+98+76+be+52+e2+cc+db+0a+d4+8b+f5+b8+49+d5+17+b8+68+22+31+0a+2c+04+52+a6+55+c2+8d+bc+06+eb+af+14+72+a3+c8+9e+c4+54+ea+52+3d+1a+04+50+8e+88+20+f0+e5+bb+42+92+5c+e6+7c+4e+ba+12+9e+e4+11+5d+b8+9c+88+89+db+36+e6+b4+f5+ea+5d+e7+17+98+b4+13+31+48+12+5e+53+" & string(66, chr$(0))

end if

end sub

private sub winsock1_close(index as integer)

winsock1(intmax).close

end sub

簡單實現TCP服務端與客戶端

1 include2 include3 include4 include5 include6 include7 include8 include9 10 tcp服務端 簡單的網路聊天程式 11 1 建立socket 12 2 為socket繫結位址埠 13 3 開始監聽socket 告訴作業系統,開...

HTTP服務端JSON服務端

最後更新日期 2014 5 18 author kagula 內容簡介 cppcms是個開源web開發框架,通過它可以很容易實現http服務和json服務,這裡介紹cppcms開發環境的搭建。寫乙個cppcms測試程式,它建立http服務,向瀏覽器返回hello,world頁面。cppcms依賴的一...

json服務端簡易實現

orm模型中宣告乙個方法,可以將例項化後物件的資料轉換為字典 式 class product detail db.model 宣告產品明細表 tablename t s product detail id db.column db.integer,primary key true color db....