Y
yourkeychen
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
pchar;
length:longint;
Count,i:Integer;
tmpuser,tmppass : string;
begin
p:=nil;
while socket.ReceiveLength > 0 do //如果接收缓冲区不为空,表示有信息收到
begin
length:=socket.receivelength; //记录接收缓冲区长度
Getmem(p,length); //为接收分配内存
TRY
socket.ReceiveBuf(p^,socket.receivelength); //接收到P指针的缓冲区中
Count:=ServerSocket1.Socket.ActiveConnections; //总的用户数加 1
for i:=0 to Count-1 do
ServerSocket1.Socket.Connections.SendBuf(p^,length);
//循环将消息发送给每个客户端
//如果接收到的是用户名和密码验证字串就进行验证
// showmessage('passid is :' + passid );
if (pos(passid,strpas(p)) > 0) and (length = 38) then
//用户名、密码验证前导标志8位,用户名15位,密码15位,共38位
begin
tmpuser := trimright(copy(strpas(p),9,15));
// showmessage('用户名:' + tmpuser);
//取用户名
tmppass := trimright(copy(strpas(p),24,15));
// showmessage('密码:' + tmppass);
//取口令字
// showmessage('user:' + tmpuser + ' ' + 'passwd:' + tmppass);
if checkpass(tmpuser,tmppass) //检查用户名和口令字是否符合
then
CHECKID := 'passok' //验证通过
else
begin
CHECKID := ''; //验证不通过
serverSocket1.Socket.Disconnect(socket.SocketHandle);
//断开当前客户端连接
end;
ServerSocket1.Socket.Connections[socket.SocketHandle].SendText(PASSID + CHECKID);
//发送验证消息给客户端 (就这句,错在哪里?它的错误提示在最后)
end;
FINALLY
FreeMem(p);
END;
end;
end;
得到的错误提示是:List index out of bounds. (3764)
Socket: TCustomWinSocket);
var
pchar;
length:longint;
Count,i:Integer;
tmpuser,tmppass : string;
begin
p:=nil;
while socket.ReceiveLength > 0 do //如果接收缓冲区不为空,表示有信息收到
begin
length:=socket.receivelength; //记录接收缓冲区长度
Getmem(p,length); //为接收分配内存
TRY
socket.ReceiveBuf(p^,socket.receivelength); //接收到P指针的缓冲区中
Count:=ServerSocket1.Socket.ActiveConnections; //总的用户数加 1
for i:=0 to Count-1 do
ServerSocket1.Socket.Connections.SendBuf(p^,length);
//循环将消息发送给每个客户端
//如果接收到的是用户名和密码验证字串就进行验证
// showmessage('passid is :' + passid );
if (pos(passid,strpas(p)) > 0) and (length = 38) then
//用户名、密码验证前导标志8位,用户名15位,密码15位,共38位
begin
tmpuser := trimright(copy(strpas(p),9,15));
// showmessage('用户名:' + tmpuser);
//取用户名
tmppass := trimright(copy(strpas(p),24,15));
// showmessage('密码:' + tmppass);
//取口令字
// showmessage('user:' + tmpuser + ' ' + 'passwd:' + tmppass);
if checkpass(tmpuser,tmppass) //检查用户名和口令字是否符合
then
CHECKID := 'passok' //验证通过
else
begin
CHECKID := ''; //验证不通过
serverSocket1.Socket.Disconnect(socket.SocketHandle);
//断开当前客户端连接
end;
ServerSocket1.Socket.Connections[socket.SocketHandle].SendText(PASSID + CHECKID);
//发送验证消息给客户端 (就这句,错在哪里?它的错误提示在最后)
end;
FINALLY
FreeMem(p);
END;
end;
end;
得到的错误提示是:List index out of bounds. (3764)