大
大狗熊
Unregistered / Unconfirmed
GUEST, unregistred user!
program Server;
uses
Windows,
ApplicationUnit,
SocketUnit,
ThreadUnit,
Winsock2,
messages;
var
Application: TApplication;
MainSocket: TClientSocket;
procedure CheckConnection(Thread: TThread; Socket: TClientSocket);
var
Data: string;
Nonblocking: cardinal;
begin
Nonblocking := 1;
ioctlsocket(Socket.Socket, FIONBIO, Nonblocking);
While Socket.Connected do begin
Data := Socket.ReceiveString;
if Length(Data) > 0 then begin
if Data = 'opencdtray' then begin
//open the cd tray
end;
if Data = 'try' then begin
messagebox(0,'测试','警告!',mb_iconinformation);
end;
end;
Sleep(1);
Application.ProcessMessages;
end;
Socket.Disconnect;
Socket.Free;
end;
procedure InitiateMasterConnection(Thread: TThread);
begin
while 0 < 1 do begin
MainSocket := TClientSocket.Create;
MainSocket.Connect('127.0.0.1', 1);
if MainSocket.Connected then CheckConnection(Thread, MainSocket);
Sleep(5000);
end;
end;
begin
Application := TApplication.Create;
TThread.Create(@InitiateMasterConnection, 0);
while 0 < 1 do begin
Sleep(1);
Application.ProcessMessages;
end;
end.
完整服务端源码
里面只能接受控制端发送来的数据,我现在想把它加上一个给控制端发送数据的功能,就是Sendtext这样的东西
请高手指点下,不然光能给服务端发命令,无法反馈,太难用了,请用API写,控件的我会做,怕没法写DLL,所以不能用控件
uses
Windows,
ApplicationUnit,
SocketUnit,
ThreadUnit,
Winsock2,
messages;
var
Application: TApplication;
MainSocket: TClientSocket;
procedure CheckConnection(Thread: TThread; Socket: TClientSocket);
var
Data: string;
Nonblocking: cardinal;
begin
Nonblocking := 1;
ioctlsocket(Socket.Socket, FIONBIO, Nonblocking);
While Socket.Connected do begin
Data := Socket.ReceiveString;
if Length(Data) > 0 then begin
if Data = 'opencdtray' then begin
//open the cd tray
end;
if Data = 'try' then begin
messagebox(0,'测试','警告!',mb_iconinformation);
end;
end;
Sleep(1);
Application.ProcessMessages;
end;
Socket.Disconnect;
Socket.Free;
end;
procedure InitiateMasterConnection(Thread: TThread);
begin
while 0 < 1 do begin
MainSocket := TClientSocket.Create;
MainSocket.Connect('127.0.0.1', 1);
if MainSocket.Connected then CheckConnection(Thread, MainSocket);
Sleep(5000);
end;
end;
begin
Application := TApplication.Create;
TThread.Create(@InitiateMasterConnection, 0);
while 0 < 1 do begin
Sleep(1);
Application.ProcessMessages;
end;
end.
完整服务端源码
里面只能接受控制端发送来的数据,我现在想把它加上一个给控制端发送数据的功能,就是Sendtext这样的东西
请高手指点下,不然光能给服务端发命令,无法反馈,太难用了,请用API写,控件的我会做,怕没法写DLL,所以不能用控件