新搭建的win2003服务器有问题
新搭建了一台win2003服务器,所有内容都是按照旧服务器设置的,能正常运转,但在做查询时有时会报错,使用的是socket通讯,实在不知哪里有问题,声明:不是全部不行,有的商户可以查询,有的商户查询不了,他们都调用同一个程序,把程序和截图粘出来,大家看下什么原因
VB程序代码如下:
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Text
Imports System.IO
Imports System.Runtime.InteropServices
Public Class StateObject
'SOCKET ID
Public workSocket As Socket = Nothing
'可接收数据大小
Public Const BufferSize As Integer = 1024 * 512
'Public Const BufferSize As Integer = 1024
'接收数据缓冲区
Public buffer(BufferSize) As Byte
'接收数据
Public sb As New StringBuilder
End Class
Public Class ESA_TCP_CLIENT
'处理结果
Public Enum ExSocketState
ExSocketSucceed = 0 '处理成功
ExSocketNoConnect = 1 '主机无连接
ExSocketUnKnown = 2 '未知状态(主机未响应)
ExSocketAllUsed = 3 '无可用端口(没有空闲状态的端口)
End Enum
Private connectDone As New ManualResetEvent(False)
Private sendDone As New ManualResetEvent(False)
Private receiveDone As New ManualResetEvent(False)
Private response As String = String.Empty
Private iTimeOutM As Integer
Private isConn As Boolean = False
Public Function SendTo(ByVal strHostIP As String, _
ByVal iPort As Integer, _
ByVal iTimeout As Integer, _
ByVal strSend As String, _
ByRef strRecv As String, _
ByVal Merch_ID As String, _
ByVal ULNm As String) As ExSocketState '增加Merch_ID,ULNm zfy 2011-1-6 用于生成Merch_ID.txt文件
On Error GoTo go_Err
Dim ipHostInfo As IPHostEntry = Dns.GetHostEntry(strHostIP)
Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
Dim remoteEP As New IPEndPoint(ipAddress, iPort)
Dim client As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
'2011-7-19 zfy
strRecv = ""
If iTimeout > 0 And iTimeout < 200000 Then '1000000
iTimeOutM = iTimeout
Else
iTimeOutM = 5000 '5000
End If
SendTo = ExSocketState.ExSocketUnKnown
client.BeginConnect(remoteEP, New AsyncCallback(AddressOf ConnectCallback), client)
If connectDone.WaitOne(iTimeOutM, False) = True Then
If isConn = True Then
Send(client, strSend, Merch_ID, ULNm) '增加Merch_ID zfy 2011-1-6 用于生成Merch_ID.txt文件 (问题出在这)
If sendDone.WaitOne(iTimeOutM, False) = True Then
If isConn = True Then
'由于测试中出现异步通讯时接收主机报文有报文不完整情况
'所以在此处修改为在连接、发送时采用异步方式,而接收数据时采用同步方式
'此处还需要考虑同步接收的超时机制,暂略
Dim state As New StateObject
state.workSocket = client
If Receive(state, Merch_ID, ULNm) Then '增加Merch_ID,ULNm zfy 2011-1-6 用于生成Merch_ID.txt文件
strRecv = state.sb.ToString()
If strRecv.Length > 10 Then
strRecv = strRecv.Substring(10, strRecv.Length - 10)
Else
strRecv = ""
End If
SendTo = ExSocketState.ExSocketSucceed
Else
SendTo = ExSocketState.ExSocketUnKnown
End If
Else
SendTo = ExSocketState.ExSocketUnKnown
End If
Else
SendTo = ExSocketState.ExSocketUnKnown
End If
Else
SendTo = ExSocketState.ExSocketNoConnect
End If
Else
SendTo = ExSocketState.ExSocketNoConnect
End If
go_Exit:
If client.Connected = True Then
client.Shutdown(SocketShutdown.Both)
End If
client.Close()
Exit Function
go_Err:
GoTo go_Exit
End Function
Public Function InitSocketAndConnect(ByVal strHostIP As String, _
ByVal iPort As Integer, _
ByVal iTimeout As Integer, _
ByVal strSend As String, _
ByRef strRecv As String, _
ByVal Merch_ID As String, _
ByVal ULNm As String) As ExSocketState
Dim strLen As Integer
For n = 1 To strSend.Length
If AscW(Mid(strSend, n, 1)) > 256 Then strLen = strLen + 2 Else strLen = strLen + 1
Next
strSend = Format(strLen, "0000000000") & strSend
Dim FileToWrite As System.IO.FileStream = System.IO.File.Create("D:\程序\ESA_OPR_New\debug\Send" + Merch_ID + "_" + ULNm + ".txt")
'Dim rByte() As Byte = Encoding.Default.GetBytes(data.ToCharArray)
Dim rByte() As Byte = Encoding.Default.GetBytes(strSend.ToCharArray)
FileToWrite.Write(rByte, 0, rByte.Length)
FileToWrite.Close()
FileToWrite = Nothing
Try
Dim port As Integer = 6501
Dim host As String = "192.168.1.10"
Dim ip As IPAddress = IPAddress.Parse(host)
Dim ipe As New IPEndPoint(ip, port) '把ip和端口转化为IPEndPoint实例
Dim c As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) '创建一个Socket
c.Connect(ipe) '连接到服务器
Dim byteData As Byte() = Encoding.Default.GetBytes(strSend)
c.Send(byteData, byteData.Length, 0) '发送测试信息
Dim recvStr As String = ""
Dim recvBytes As Byte() = New Byte(1023) {}
Dim bytes As Integer
bytes = c.Receive(recvBytes, recvBytes.Length, 0) '从服务器端接受返回信息
recvStr += Encoding.ASCII.GetString(recvBytes, 0, bytes)
'显示服务器返回信息
c.Close()
Catch e As ArgumentNullException
Catch e As SocketException
'Console.WriteLine("SocketException: {0}", e)
End Try
End Function