请问modem连modem的点对点传输程序怎么做? (100分)

  • 主题发起人 主题发起人 ygsoft
  • 开始时间 开始时间
Y

ygsoft

Unregistered / Unconfirmed
GUEST, unregistred user!
首先说明不用网卡,也就是说不能配TCP/IP
如果有源码,请给我一个,多谢了
 
srv


unit Main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, ScktComp;

type
TMainForm = class(TForm)
ServerSocket: TServerSocket;
Button1: TButton;
Button2: TButton;
StatusBar: TStatusBar;
Memo: TMemo;
Edit: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ServerSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure EditChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

{$R *.DFM}

Const
BufLen:Integer=30*1024;

Type
Buffer=Array[1..1] of Byte;

Var
MemStream:TMemoryStream;
SocketStream:TWinSocketStream;
FOut:File;
Buf:^Buffer;
Temp,Code:Longint;
s,s1:String;

procedure TMainForm.Button1Click(Sender: TObject);
begin
ServerSocket.Port:=3366;
ServerSocket.ServerType:=stNonBlocking;
ServerSocket.Open;
StatusBar.SimpleText:='Socket open!';
GetMem(Buf,BufLen);
AssignFile(FOut,'test.bin');
Rewrite(FOut,1);
Memo.Clear;
end;

procedure TMainForm.Button2Click(Sender: TObject);
begin
CloseFile(FOut);
FreeMem(Buf);
ServerSocket.Close;
StatusBar.SimpleText:='Socket closed!';
end;

procedure TMainForm.ServerSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
If Socket.Connected Then
Begin
Try
Temp:=Socket.ReceiveBuf(Buf^,BufLen);
While Temp>=0 do
Begin
If Temp>0 Then BlockWrite(FOut,Buf^,Temp);
Temp:=Socket.ReceiveBuf(Buf^,BufLen);
End;
Finally
End;
End;
end;

procedure TMainForm.EditChange(Sender: TObject);
begin
Val(Edit.Text,BufLen,Code);
Str(BufLen,s);
Label1.Caption:=s;
end;

end.
 
cnt


unit main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, ComCtrls, StdCtrls;

type
TMainForm = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
StatusBar: TStatusBar;
OpenDialog: TOpenDialog;
ClientSocket: TClientSocket;
Memo: TMemo;
Edit: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure EditChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

{$R *.DFM}

Const
BufLen:Integer=30*1024;

Type
Buffer=Array[1..1] of Byte;

Var
MemStream:TMemoryStream;
Fin:File;
Buf:^Buffer;
Temp:Longint;
Code:Integer;
s,s1:String;

procedure TMainForm.Button1Click(Sender: TObject);
begin
ClientSocket.Port:=3366;
ClientSocket.ClientType:=ctNonBlocking;
ClientSocket.Address:='127.0.0.1';
ClientSocket.Open;
StatusBar.SimpleText:='Socket open!';
end;

procedure TMainForm.Button3Click(Sender: TObject);
begin
ClientSocket.Close;
StatusBar.SimpleText:='Socket closed!';
end;

procedure TMainForm.Button2Click(Sender: TObject);
Var
sending,sent:Longint;
index:Longint;
begin
If OpenDialog.Execute Then
Begin
Memo.Clear;
GetMem(Buf,BufLen);
AssignFile(Fin,OpenDialog.FileName);
Try
Reset(Fin,1);
BlockRead(Fin,Buf^,BufLen,Temp);
Str(temp,s);
sent:=0;
Index:=1;
StatusBar.SimpleText:='File senting!';
While Temp>0 do
Begin
While sent<temp do
Begin
sending:=ClientSocket.Socket.SendBuf(Buf^[index],Temp);
If sending<>-1 Then
Begin
sent:=sent+sending;
index:=index+sending;
temp:=temp-sending;
End;
End;
Str(sent,s1);
Memo.Lines.Add('Read:'+s+' Send:'+s1);
BlockRead(Fin,Buf^,BufLen,Temp);
sent:=0;
Index:=1;
Str(temp,s);
End;
Finally
CloseFile(Fin);
FreeMem(Buf);
End;
End;
StatusBar.SimpleText:='File send!';
end;

procedure TMainForm.EditChange(Sender: TObject);
begin
Val(Edit.Text,BufLen,Code);
Str(BufLen,s);
Label1.Caption:=s;
end;

end.
 
有没有用Modem连接的,你这个好像是用网卡ip
 
难道modem就不是用ip的??难道ip=网卡?
 
用modem可以直接copy,跟局域网一样
 
可以穿过网关吗。
也就是可以跨网段传送吗
 
楼上问到关键的地方了
 
你要做个Modom的点对点的数据传送吗?

如果是Modom,直接读取串口 写串口是不是就行了..?
 
tcp/ip本来就可以跨网段的,要不,还要tpc/ip干什么?
 
通过TCP/IP速度不快
 
Modom用串口慢,我测试过最快11K,不过9.6K是最温定
Modom用TCP/IP最高可得56K
 
MODEM你说的是专线连接,所以传输的数据量一帮不会很大;
我得观点,仅供参考:
拨号拨通以后操作远程计算机的串口,进行串口通讯即可解决问题的
我以前做过的;
另外我赞成:firstrose 不过当初使用mscomm控件写的;

 
窑洞里找TurboPower Async Prof 4.05
http://202.117.210.31/delphi/
这个控件里面带有demo,你可以做测试的!
 
可以用SPCOmm做拨号程序(用AT命令),我就是这样做的
 
搂主:
如果 firehose 的有效的话,是要利用 NT /2K的拨号服务器的机制.这样会分配给远程的拨入的客户端IP,然后就可以是基于 Socket的传输程序了.

不然的话,就是基于串口的数据传输.至于如何定义协议 你自己定义一下就行了.
 
后退
顶部