W
wanglong2
Unregistered / Unconfirmed
GUEST, unregistred user!
很简单的发送和接收的程序,如果发送和接收端写在同一个程序里,就好使,分别写成两个程序,就收到的是乱码,为什么啊??<br>发送端:<br>type<br><br> tjl = packed record<br><br> username: string;<br> email:string;<br> end;<br><br> pjl = ^tjl;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>type<br> tchararray = array[0..sizeof(tjl)] of char;<br> pchararray = ^tchararray;<br>var<br> jl: tjl;<br>begin<br> jl.username := '王龙';<br> jl.email := 'w@l';<br> ClientSocket1.Socket.SendBuf(pchararray(@jl)^, sizeof(tjl))<br>end;<br><br>接收端:<br>type<br><br> tjl = packed record<br> username: string;<br> email:string;<br> end;<br><br> pjl = ^tjl;<br><br><br>procedure TForm1.ServerSocket1ClientRead(Sender: TObject;<br> Socket: TCustomWinSocket);<br><br> var<br> buf: array[0..500] of char;<br> len:integer;<br>begin<br> len:=socket.ReceiveLength;<br> socket.ReceiveBuf(buf,len);<br> edit1.text := pjl(@buf)^.email;<br>end;