如何实现局域网中声音的实时传输?(急待解决)(50分)

  • 主题发起人 主题发起人 jianghua9019
  • 开始时间 开始时间
J

jianghua9019

Unregistered / Unconfirmed
GUEST, unregistred user!
我的毕业设计是做一个局域网语音通话软件,这个月底就要交程序了,可是我现在还没有
做出来,我参考别人的代码用ACM控件做了一个基于C/S结构的程序,可是一点声音也没有,
请各位高手指导一下小弟,我将不胜感激!我的代码如下:
unit main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls, ACMWaveOut, ACMWaveIn, ACMDialog;

type
TMainForm = class(TForm)
ConnectButton: TButton;
AddrEdit: TEdit;
Label1: TLabel;
ServerSocket: TServerSocket;
ClientSocket: TClientSocket;
ACMDialog: TACMDialog;
ACMWaveIn: TACMWaveIn;
ACMWaveOut: TACMWaveOut;
DropButton: TButton;
Memo: TMemo;
Label2: TLabel;
ClearButton: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ConnectButtonClick(Sender: TObject);
procedure DropButtonClick(Sender: TObject);
procedure ClearButtonClick(Sender: TObject);
procedure ServerSocketClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocketConnecting(Sender: TObject;
Socket: TCustomWinSocket);
procedure ACMWaveInData(data: Pointer; size: Integer);
procedure ServerSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

{$R *.DFM}

Const
BufLen:Integer=1024*1024;

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

Var
MemStream:TMemoryStream;
Buf:^Buffer;
IsServer:Boolean;
Client:TCustomWinSocket;

procedure TMainForm.FormCreate(Sender: TObject);
Var
Format:Pointer;
begin
ServerSocket.Port:=3366;
ServerSocket.ServerType:=stNonBlocking;
ServerSocket.Open;
GetMem(Buf,BufLen);
Memo.Lines.Add('Local server srarted.');
Format:=ACMDialog.OpenDialog;
If Format=nil Then Exit;
ACMWaveOut.Open(Format);
ACMWaveIn.Open(Format);
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
FreeMem(Buf);
ACMWaveIn.Close;
ACMWaveOut.Close;
ServerSocket.Close;
Memo.Lines.Add('Local server shutdown.');
end;

procedure TMainForm.ConnectButtonClick(Sender: TObject);
begin
ClientSocket.Port:=3366;
ClientSocket.ClientType:=ctNonBlocking;
ClientSocket.Address:=AddrEdit.Text;
ClientSocket.Open;
IsServer:=False;
end;

procedure TMainForm.DropButtonClick(Sender: TObject);
begin
ClientSocket.Close;
end;

procedure TMainForm.ClearButtonClick(Sender: TObject);
begin
Memo.Clear;
end;

procedure TMainForm.ServerSocketClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo.Lines.Add('A client connected.');
IsServer:=True;
Client:=Socket;
end;

procedure TMainForm.ServerSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo.Lines.Add('A client droped.');
end;

procedure TMainForm.ClientSocketConnecting(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo.Lines.Add('Connecting to server '+AddrEdit.Text);
end;

procedure TMainForm.ACMWaveInData(data: Pointer; size: Integer);
Var
sending,sent,index,temp:Longint;
s:String;
begin
{ temp:=size;
sent:=0;
Index:=1;
While sent<temp do
Begin
sending:=ClientSocket.Socket.SendBuf(BufPointer(data)[index],Temp);
If sending<>-1 Then
Begin
sent:=sent+sending;
index:=index+sending;
temp:=temp-sending;
End;
End;}
Case IsServer of
True:
Begin
If Client.Connected Then
Begin
Client.SendBuf(data^,size);
End;
End;
False:
Begin
If ClientSocket.Socket.Connected Then
Begin
Str(ClientSocket.Socket.SendBuf(data^,size),s);
Memo.Lines.Add('Sent '+s);
End;
End;
End;
end;

procedure TMainForm.ServerSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
Var
temp:Longint;
begin
temp:=Socket.ReceiveBuf(Buf^,BufLen);
If NOT IsServer Then Exit;
ACMWaveOut.PlayBack(Buf,temp);
end;

procedure TMainForm.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
Var
temp:Longint;
begin
temp:=Socket.ReceiveBuf(Buf^,BufLen);
If IsServer Then Exit;
ACMWaveOut.PlayBack(Buf,temp);
end;

end.
希望对这方面有研究的朋友指点我。
 
后退
顶部