delphi software
this was done using delphi3, based on a component (and its example code) 'twsocket' by francois piette. its just the .pas part of it. you can download all of the project here: oscclient.zip
implemented are the following types:
i = 32 bit integer.
s = a multiple-of-4-byte-padded ascii string which represents a Symbol object.
S = a multiple-of-4-byte-padded ascii string which represents a String object.
c = an ascii character, sent as 32 bits.
for the double type we couldnbt figure out how to encode it...:
d = 64 bit double float. The native floating point format for SuperCollider.
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: François PIETTE
Copyright: You can use this software freely, at your own risks
Creation: April 4, 1997
Version: 2.02
Object: Demo program to show how to use TWSocket object to broadcast
UDP messages on the network. Use UDPLstn to listen to those
UDP messages, or other UDP messages.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit oscclientp;
interface
uses
WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
FormPos, StdCtrls, Wsocket, IniFiles,cgitool;
type
TMainForm = class(TForm)
WSocket: TWSocket;
SendButton: TButton;
MessageEdit: TEdit;
PortEdit: TEdit;
Label1: TLabel;
Label2: TLabel;
LocalPortEdit: TEdit;
AnyPortCheckBox: TCheckBox;
Label3: TLabel;
fstringedit: TEdit;
Label4: TLabel;
Label5: TLabel;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label6: TLabel;
ScrollBar1: TScrollBar;
procedure FormShow(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure SendButtonClick(Sender: TObject);
procedure AnyPortCheckBoxClick(Sender: TObject);
procedure LocalPortEditChange(Sender: TObject);
procedure parsefstring(sender:tobject);
procedure ScrollBar1Change(Sender: TObject);
private
FIniFileName : String;
FSectionName : String;
FKeyName : String;
end;
var
MainForm: TMainForm;
implementation
var fstring,flstring:string;
values:array[0..10] of tedit;
labels:array[0..10] of tlabel;
types:array[0..10] of char;
param:array[1..4] of integer;
cgistring:string;
setting:boolean;
vertpos:integer;
par:boolean;
{$R *.DFM}
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TMainForm.FormShow(Sender: TObject);
const
FirstTime : Boolean = TRUE;
var
IniFile : TIniFile;
i:integer;
procedure parsecgistring;
var tempstr:string;
begin
//weapon
param[1]:=strtoint(cgistring[1]);
tempstr:='';
i:=3;
while cgistring[i]<>'a' do
begin
tempstr:=tempstr+cgistring[i];
inc(i);
end;
param[2]:=strtoint(tempstr);
inc(i);
tempstr:='';
while cgistring[i]<>'a' do
begin
tempstr:=tempstr+cgistring[i];
inc(i);
end;
param[3]:=strtoint(tempstr);
inc(i);
tempstr:='';
while cgistring[i]<>'a' do
begin
tempstr:=tempstr+cgistring[i];
inc(i);
end;
param[4]:=strtoint(tempstr);
end;
procedure sendresponse;
var cgi:tcgi;
begin
cgi := tCGI.Create;
with cgi do
begin
writeln( 'Content-type: text/html' );
writeln;
writeln('<html><head><SCRIPT LANGUAGE="JavaScript">');
writeln('function re() {');
writeln('window.location.href="http://134.100.176.32/lasergun/sliders.html"');
writeln('}');
writeln('</script>');
writeln('<body onload="re()"></body></html>');
// CGI-Verarbeitung
end;
// CGI-Objekt entfernen
cgi.destroy;
end;
begin
par:=false;
if paramcount<>0 then
begin
cgistring:=paramstr(1);
par:=true;
parsecgistring;
end;
sendresponse;
setting:=false;
if FirstTime then begin
FirstTime := FALSE;
FIniFileName := 'UdpSend';
FSectionName := 'Windows';
FKeyName := 'MainForm';
// LoadFormPos(Self, FIniFilename, FSectionName, FKeyName);
IniFile := TIniFile.Create(FIniFileName);
PortEdit.Text := IniFile.ReadString('data', 'Port', '600');
LocalPortEdit.Text := IniFile.ReadString('data', 'LocalPort', '0');
MessageEdit.Text := IniFile.ReadString('data', 'Message', '');
IniFile.Free;
portedit.text:='54321';
parsefstring(self);
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TMainForm.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
var
IniFile : TIniFile;
begin
SaveFormPos(Self, FIniFilename, FSectionName, FKeyName);
IniFile := TIniFile.Create(FIniFileName);
IniFile.WriteString('data', 'Port', PortEdit.Text);
IniFile.WriteString('data', 'LocalPort', LocalPortEdit.Text);
IniFile.WriteString('data', 'Message', MessageEdit.Text);
IniFile.Free;
end;
procedure tmainform.parsefstring(sender:tobject);
{
i = 32 bit integer.
d = 64 bit double float. The native floating point format for SuperCollider.
s = a multiple-of-4-byte-padded ascii string which represents a Symbol object.
S = a multiple-of-4-byte-padded ascii string which represents a String object.
c = an ascii character, sent as 32 bits.
r = a 32 bit RGBA color.
T = true. No bytes are allocated in the argument data.
F = false. No bytes are allocated in the argument data.
[ = indicates the beginning of an Array. The tags following are for data
in the Array until a close brace tag is reached.
] = indicates the end of an Array.
}
procedure makeedit(s:char);
begin
types[vertpos]:=s;
values[vertpos]:=tedit.create(self);
with values[vertpos] do
begin
left:=10;
top:=vertpos*25+25;
tag:=vertpos;
parent:=groupbox1;
show;
end;
labels[vertpos]:=tlabel.create(self);
with labels[vertpos] do
begin
caption:=inttostr(vertpos)+'('+s+')';
left:=10;
top:=vertpos*25+25;
parent:=groupbox2;
show;
end;
inc(vertpos);
end;
var j,c:integer;
begin
if not setting then
begin
c:=groupbox1.controlcount-1;
with groupbox1 do
begin
for j:=c downto 0 do controls[j].destroy;
end;
vertpos:=0;
fstring:=fstringedit.text;
flstring:='';
for j:=1 to length(fstring) do
begin
case fstring[j] of
'i':begin
flstring:=flstring+'integer, ';
makeedit('i');
end;
'd':begin
flstring:=flstring+'double, ';
makeedit('d');
end;
's':begin
flstring:=flstring+'symbol, ';
makeedit('s');
end;
'S':begin
flstring:=flstring+'string, ';
makeedit('s');
end;
'c':begin
flstring:=flstring+'char, ';
makeedit('c');
end;
'r':begin
flstring:=flstring+'RGBA color, ';
makeedit('r');
end;
'T':flstring:=flstring+'TRUE, ';
'F':flstring:=flstring+'FALSE, ';
'[':begin
flstring:=copy(flstring,0,length(flstring)-2);
flstring:=flstring+'[';
end;
']':begin
flstring:=copy(flstring,0,length(flstring)-2);
flstring:=flstring+']';
end;
else
begin
setting:=true;
fstringedit.text:=copy(fstringedit.text,0,length(fstringedit.text)-1);
setting:=false;
end;
end;
end;
// flstring:=copy(flstring,0,length(flstring)-2);
label5.caption:=flstring;
end;
// insert params
if par then
begin
with groupbox1 do
begin
for j:=0 to groupbox1.controlcount-1 do
begin
with controls[j] as tedit do text:=inttostr(param[j+1]);
end;
end;
end;
sendbuttonclick(self);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TMainForm.SendButtonClick(Sender: TObject);
var sendstring,text1:string;
k,rest,i,len:integer;
val:byte;
function makec(val:char):string;
begin
result:=chr(0)+chr(0)+chr(0)+val;
end;
function makei(vals:string):string;
var tmp:byte;
k:integer;
val:integer;
begin
result:='';
val:=strtoint(vals);
for k:=1 to 4 do
begin
tmp:=val and $00ff;
result:=chr(tmp)+result;
val:=val shr 8;
end;
end;
function maked(val:double):string;
var tmp:byte;
k:integer;
begin
result:='';
for k:=1 to 8 do
begin
// tmp:=val and $00ff;
result:=chr(tmp)+result;
// val:=val shr 8;
end;
end;
function makes(val:string):string;
var tmp:byte;
k,l:integer;
begin
result:=val;
k:=(length(val)) mod 4;
if k<>0 then for l:=1 to 4-k do result:=result+chr(0);
if k=0 then for l:=1 to 4 do result:=result+chr(0);
end;
begin
WSocket.Proto := 'udp';
WSocket.Addr := '134.100.176.31';
WSocket.Port := PortEdit.Text;
WSocket.LocalPort := LocalPortEdit.Text;
WSocket.Connect;
sendstring:=makes(messageedit.text)+makes(','+fstringedit.text);
label6.caption:=sendstring;
for i:=0 to vertpos-1 do
begin
{ k:=0;
repeat
if groupbox1.controls[k] is tedit
then with groupbox1.controls[k] as tedit do
if tag=i then text1:=text;
inc(k);
until k=groupbox1.controlcount;
}
with groupbox1.controls[i] as tedit do text1:=text;
//label5.caption:=text1;
//showmessage(text1);
case types[i] of
'i':sendstring:=sendstring+makei(text1);
's':sendstring:=sendstring+makes(text1);
'S':sendstring:=sendstring+makes(text1);
'c':sendstring:=sendstring+makec(text1[1]);
end;
// showmessage('lala');
end;
WSocket.SendStr(sendstring);
WSocket.Close;
close;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TMainForm.AnyPortCheckBoxClick(Sender: TObject);
begin
if AnyPortCheckBox.Checked then
LocalPortEdit.Text := '0';
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TMainForm.LocalPortEditChange(Sender: TObject);
begin
AnyPortCheckBox.Checked := (LocalPortEdit.Text = '0');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TMainForm.ScrollBar1Change(Sender: TObject);
begin
with values[0] as tedit do text:=inttostr(scrollbar1.position);
sendbuttonclick(self);
end;
end.

Link to this Page