首页
社区
课程
招聘
[旧帖] 翻译几句php源码到vb.net 0.00雪花
发表于: 2016-11-2 14:38 3136

[旧帖] 翻译几句php源码到vb.net 0.00雪花

2016-11-2 14:38
3136
$sss = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);//这里应该确定协议

socket_connect($sss, $gamed_ip, $GamedbPort));//通过IP端口连接服务器

$senddata='8D49088000000000000100';//16进制的包头

socket_write($sss,pack('H*',$senddata));//发送

$fb_head = socket_read($sss,2048 );//接收

$fb_head_hex_un = unpack('H*',$fb_head)

此php源码是通过sock方法向服务器数据库发送一个数据包头'8D49088000000000000100'然后返回数据库当前段信息 图片中我echo了几个返回值 最长的是我想要的。现在我想用VB.net实现此功能球大神给个写法。以下是我的写法但是没有得到返回值 放上来看看吧哪里写的不对呢
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
    Dim clientSocket As New System.Net.Sockets.TcpClient()
    Dim serverStream As NetworkStream

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim serverStream As NetworkStream = clientSocket.GetStream()
        
        'Dim TestArray() As String = Split("8D 49 08 80 00 00 00 00 00 01 00")
        'Dim hexBytes() As Byte
        'ReDim hexBytes(TestArray.Length - 1)
        'Dim i As Integer
        'For i = 0 To TestArray.Length - 1
        '    hexBytes(i) = Val("&h" & TestArray(i))
        '    ListBox1.Items.Add(TestArray(i))
        'Next
        'serverStream.Write(hexBytes, 0, hexBytes.Length)

        Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes("&h" & "8D49088000000000000100")
        serverStream.Write(outStream, 0, outStream.Length)

        serverStream.Flush()

        Dim inStream(10024) As Byte
        serverStream.Read(inStream, 0, CInt(clientSocket.ReceiveBufferSize))
        Dim returndata As String = System.Text.Encoding.ASCII.GetString(inStream)
        msg("返回数据: " + returndata)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles MyBase.Load


        msg("无数据")
        clientSocket.Connect("192.168.200.101", 29400)
    End Sub

    Sub msg(ByVal mesg As String)
        TextBox1.Text = " >> " + mesg
    End Sub
End Class



谁能解决可以联系我QQ583895163 我启动数据库供调试 另外就是这个悬赏我可以补加,这里放多了没人解答就浪费了 急求

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

上传的附件:
收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 12
活跃值: (515)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
用sokit搭一个socket服务器看看你代码发送出去的内容有什么不同
2016-12-9 12:58
0
雪    币: 1
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
服务器返回数据不是即时的,要放一个loop监听服务器回应

Dim inStream(10024) As Byte
Do
      serverStream.Read(inStream, 0, CInt(clientSocket.ReceiveBufferSize))
      Dim returndata As String = System.Text.Encoding.ASCII.GetString(inStream)
      msg("返回数据: " + returndata)
Loop While serverStream.DataAvailable
2016-12-13 16:12
0
雪    币: 3
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
第一个问题是 Dim inStream(10024) As Byte serverStream.Read(InStream, 0, Clnt(clientSocket.ReceiveBufferSize)), 因为
clientSocket.ReceiveBufferSize 是 65536, 比 inStream 大 (10024), 因此不能收到数据。 改成 Dim inStream(100000) As Byte
serverStream.Read(InStream, 0, Clnt(clientSocket.ReceiveBufferSize)) 就会解决这个问题。

第二个问题是 Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes("&h" & "8D49088000000000000100"),
你要发送十六进制字符串(8D49088000000000000100) 的话, 最好不要先把它转换成 ascii, 改成 Dim outStream As Byte() =
System.Text.Encoding.Default.GetBytes("8D49088000000000000100") 即可。
2016-12-20 22:22
0
游客
登录 | 注册 方可回帖
返回