Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GIO Socket Server/Client Example

  • Loading branch information...
commit 4d1a627f994475c3026b02d86200a54b0a300af7 1 parent 90e42f1
@Wutzara authored
View
20 src/basic-gio/socket-example/Makefile
@@ -0,0 +1,20 @@
+CC=gcc
+CFLAGS=-c -Wall `pkg-config --cflags gobject-2.0 gio-2.0` -g
+LDFLAGS= `pkg-config --libs gobject-2.0 gio-2.0`
+SOURCES_CLIENT=hsr-proxy.c hsr-icalc.c hsr-client.c
+SOURCES_SERVER=hsr-server.c hsr-adapter.c hsr-calc-impl.c hsr-icalc.c
+OBJECTS_CLIENT=$(SOURCES_CLIENT:.c=.o)
+OBJECTS_SERVER=$(SOURCES_SERVER:.c=.o)
+EXECUTABLE_CLIENT=client
+EXECUTABLE_SERVER=server
+
+all: $(SOURCES_CLIENT) $(SOURCES_SERVER) $(EXECUTABLE_CLIENT) $(EXECUTABLE_SERVER)
+
+$(EXECUTABLE_CLIENT): $(OBJECTS_CLIENT)
+ $(CC) $(LDFLAGS) $(OBJECTS_CLIENT) -o $@
+
+$(EXECUTABLE_SERVER): $(OBJECTS_SERVER)
+ $(CC) $(LDFLAGS) $(OBJECTS_SERVER) -o $@
+
+.c.o:
+ $(CC) $(CFLAGS) $< -o $@
View
BIN  src/basic-gio/socket-example/diagramm.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
563 src/basic-gio/socket-example/diagramm.svg
@@ -0,0 +1,563 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ height="620"
+ version="1.1"
+ viewBox="0 0 841.88975 496.00001"
+ width="1052.3622"
+ id="svg2"
+ inkscape:version="0.48.2 r9819"
+ sodipodi:docname="diagramm.svg"
+ inkscape:export-filename="/home/wutzara/Studium/VS/studium-vs/src/uebung01/diagramm.png"
+ inkscape:export-xdpi="95.606529"
+ inkscape:export-ydpi="95.606529">
+ <metadata
+ id="metadata112">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="1"
+ inkscape:pageshadow="2"
+ inkscape:window-width="1280"
+ inkscape:window-height="965"
+ id="namedview110"
+ showgrid="false"
+ inkscape:object-paths="false"
+ inkscape:zoom="0.52408178"
+ inkscape:cx="567.53986"
+ inkscape:cy="278.00952"
+ inkscape:window-x="0"
+ inkscape:window-y="27"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="svg2" />
+ <defs
+ id="defs4">
+ <marker
+ inkscape:stockid="Arrow1Mend"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="Arrow1Mend"
+ style="overflow:visible">
+ <path
+ id="path3989"
+ d="M 0,0 5,-5 -12.5,0 5,5 0,0 z"
+ style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none"
+ transform="matrix(-0.4,0,0,-0.4,-4,0)"
+ inkscape:connector-curvature="0" />
+ </marker>
+ <marker
+ inkscape:stockid="Arrow1Lend"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="Arrow1Lend"
+ style="overflow:visible">
+ <path
+ id="path3983"
+ d="M 0,0 5,-5 -12.5,0 5,5 0,0 z"
+ style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none"
+ transform="matrix(-0.8,0,0,-0.8,-10,0)"
+ inkscape:connector-curvature="0" />
+ </marker>
+ </defs>
+ <g
+ id="g3179"
+ transform="translate(-230.49838,51.554188)">
+ <rect
+ height="60.8125"
+ style="fill:#fefece;stroke:#a80036;stroke-width:1.5"
+ width="300"
+ x="501.5"
+ y="8.5"
+ id="rect8" />
+ <ellipse
+ cx="622.75"
+ cy="24.5"
+ rx="11"
+ ry="11"
+ style="fill:#b4a7e5;stroke:#a80036;stroke-width:1"
+ id="ellipse10"
+ sodipodi:cx="622.75"
+ sodipodi:cy="24.5"
+ sodipodi:rx="11"
+ sodipodi:ry="11"
+ d="m 633.75,24.5 c 0,6.075132 -4.92487,11 -11,11 -6.07513,0 -11,-4.924868 -11,-11 0,-6.075132 4.92487,-11 11,-11 6.07513,0 11,4.924868 11,11 z" />
+ <path
+ d="m 618.6719,20.2656 0,-2.1562 7.3906,0 0,2.1562 -2.4687,0 0,8.0782 2.4687,0 0,2.1562 -7.3906,0 0,-2.1562 2.4687,0 0,-8.0782 -2.4687,0 z"
+ id="path12"
+ inkscape:connector-curvature="0" />
+ <text
+ font-size="12"
+ font-style="italic"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="49"
+ x="643.25"
+ y="29.5156"
+ id="text14"
+ style="font-size:12px;font-style:italic;fill:#000000">HsrIcalc</text>
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="502.5"
+ x2="800.5"
+ y1="40.5"
+ y2="40.5"
+ id="line16" />
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="502.5"
+ x2="800.5"
+ y1="48.5"
+ y2="48.5"
+ id="line18" />
+ <ellipse
+ cx="512.5"
+ cy="60.4063"
+ rx="3"
+ ry="3"
+ style="fill:#84be84;stroke:#038048;stroke-width:1"
+ id="ellipse20"
+ sodipodi:cx="512.5"
+ sodipodi:cy="60.4063"
+ sodipodi:rx="3"
+ sodipodi:ry="3"
+ d="m 515.5,60.4063 c 0,1.656854 -1.34315,3 -3,3 -1.65685,0 -3,-1.343146 -3,-3 0,-1.656855 1.34315,-3 3,-3 1.65685,0 3,1.343145 3,3 z" />
+ <text
+ font-size="11"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="274"
+ x="521.5"
+ y="63.5"
+ id="text22"
+ style="font-size:11px;fill:#000000">hsr_icalc_add(HsrIcalc *self, gint a, gint b) : gint</text>
+ </g>
+ <g
+ id="g3169"
+ transform="translate(-409.09647,235.87079)">
+ <rect
+ height="60.8125"
+ style="fill:#fefece;stroke:#a80036;stroke-width:1.5"
+ width="188"
+ x="457"
+ y="142.5"
+ id="rect24" />
+ <ellipse
+ cx="519.75"
+ cy="158.5"
+ rx="11"
+ ry="11"
+ style="fill:#add1b2;stroke:#a80036;stroke-width:1"
+ id="ellipse26"
+ sodipodi:cx="519.75"
+ sodipodi:cy="158.5"
+ sodipodi:rx="11"
+ sodipodi:ry="11"
+ d="m 530.75,158.5 c 0,6.07513 -4.92487,11 -11,11 -6.07513,0 -11,-4.92487 -11,-11 0,-6.07513 4.92487,-11 11,-11 6.07513,0 11,4.92487 11,11 z" />
+ <path
+ d="m 522.7188,164.1406 q -0.5782,0.2969 -1.2188,0.4453 -0.6406,0.1485 -1.3437,0.1485 -2.5,0 -3.8204,-1.6485 -1.3203,-1.6484 -1.3203,-4.7734 0,-3.125 1.3203,-4.7812 1.3204,-1.6563 3.8204,-1.6563 0.7031,0 1.3515,0.1563 0.6485,0.1562 1.211,0.4531 l 0,2.7187 q -0.625,-0.5781 -1.2188,-0.8515 -0.5937,-0.2735 -1.2187,-0.2735 -1.3438,0 -2.0313,1.0703 -0.6875,1.0704 -0.6875,3.1641 0,2.0938 0.6875,3.1641 0.6875,1.0703 2.0313,1.0703 0.625,0 1.2187,-0.2735 0.5938,-0.2734 1.2188,-0.8515 l 0,2.7187 z"
+ id="path28"
+ inkscape:connector-curvature="0" />
+ <text
+ font-size="12"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="54"
+ x="540.25"
+ y="163.51559"
+ id="text30"
+ style="font-size:12px;fill:#000000">HsrProxy</text>
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="458"
+ x2="644"
+ y1="174.5"
+ y2="174.5"
+ id="line32" />
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="458"
+ x2="644"
+ y1="182.5"
+ y2="182.5"
+ id="line34" />
+ <ellipse
+ cx="468"
+ cy="194.4063"
+ rx="3"
+ ry="3"
+ style="fill:#84be84;stroke:#038048;stroke-width:1"
+ id="ellipse36"
+ sodipodi:cx="468"
+ sodipodi:cy="194.4063"
+ sodipodi:rx="3"
+ sodipodi:ry="3"
+ d="m 471,194.4063 c 0,1.65685 -1.34315,3 -3,3 -1.65685,0 -3,-1.34315 -3,-3 0,-1.65686 1.34315,-3 3,-3 1.65685,0 3,1.34314 3,3 z" />
+ <text
+ font-size="11"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="162"
+ x="477"
+ y="197.5"
+ id="text38"
+ style="font-size:11px;fill:#000000">hsr_proxy_new() : HsrProxy*</text>
+ </g>
+ <g
+ id="g3189"
+ transform="translate(-154.64106,8.5848885)">
+ <rect
+ height="60.8125"
+ style="fill:#fefece;stroke:#a80036;stroke-width:1.5"
+ width="230"
+ x="680.5"
+ y="142.5"
+ id="rect40" />
+ <ellipse
+ cx="755.25"
+ cy="158.5"
+ rx="11"
+ ry="11"
+ style="fill:#add1b2;stroke:#a80036;stroke-width:1"
+ id="ellipse42"
+ sodipodi:cx="755.25"
+ sodipodi:cy="158.5"
+ sodipodi:rx="11"
+ sodipodi:ry="11"
+ d="m 766.25,158.5 c 0,6.07513 -4.92487,11 -11,11 -6.07513,0 -11,-4.92487 -11,-11 0,-6.07513 4.92487,-11 11,-11 6.07513,0 11,4.92487 11,11 z" />
+ <path
+ d="m 758.2188,164.1406 q -0.5782,0.2969 -1.2188,0.4453 -0.6406,0.1485 -1.3437,0.1485 -2.5,0 -3.8204,-1.6485 -1.3203,-1.6484 -1.3203,-4.7734 0,-3.125 1.3203,-4.7812 1.3204,-1.6563 3.8204,-1.6563 0.7031,0 1.3515,0.1563 0.6485,0.1562 1.211,0.4531 l 0,2.7187 q -0.625,-0.5781 -1.2188,-0.8515 -0.5937,-0.2735 -1.2187,-0.2735 -1.3438,0 -2.0313,1.0703 -0.6875,1.0704 -0.6875,3.1641 0,2.0938 0.6875,3.1641 0.6875,1.0703 2.0313,1.0703 0.625,0 1.2187,-0.2735 0.5938,-0.2734 1.2188,-0.8515 l 0,2.7187 z"
+ id="path44"
+ inkscape:connector-curvature="0" />
+ <text
+ font-size="12"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="72"
+ x="775.75"
+ y="163.51559"
+ id="text46"
+ style="font-size:12px;fill:#000000">HsrCalcImpl</text>
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="681.5"
+ x2="909.5"
+ y1="174.5"
+ y2="174.5"
+ id="line48" />
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="681.5"
+ x2="909.5"
+ y1="182.5"
+ y2="182.5"
+ id="line50" />
+ <ellipse
+ cx="691.5"
+ cy="194.4063"
+ rx="3"
+ ry="3"
+ style="fill:#84be84;stroke:#038048;stroke-width:1"
+ id="ellipse52"
+ sodipodi:cx="691.5"
+ sodipodi:cy="194.4063"
+ sodipodi:rx="3"
+ sodipodi:ry="3"
+ d="m 694.5,194.4063 c 0,1.65685 -1.34315,3 -3,3 -1.65685,0 -3,-1.34315 -3,-3 0,-1.65686 1.34315,-3 3,-3 1.65685,0 3,1.34314 3,3 z" />
+ <text
+ font-size="11"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="204"
+ x="700.5"
+ y="197.5"
+ id="text54"
+ style="font-size:11px;fill:#000000">hsr_calc_impl_new () : HsrCalcImpl*</text>
+ </g>
+ <g
+ id="g3140"
+ transform="translate(-32.84177,164.59583)">
+ <rect
+ height="48"
+ style="fill:#fefece;stroke:#a80036;stroke-width:1.5"
+ width="88"
+ x="120.5"
+ y="15"
+ id="rect56" />
+ <ellipse
+ cx="135.5"
+ cy="31"
+ rx="11"
+ ry="11"
+ style="fill:#add1b2;stroke:#a80036;stroke-width:1"
+ id="ellipse58"
+ sodipodi:cx="135.5"
+ sodipodi:cy="31"
+ sodipodi:rx="11"
+ sodipodi:ry="11"
+ d="m 146.5,31 c 0,6.075132 -4.92487,11 -11,11 -6.07513,0 -11,-4.924868 -11,-11 0,-6.075132 4.92487,-11 11,-11 6.07513,0 11,4.924868 11,11 z" />
+ <path
+ d="m 138.4688,36.6406 q -0.5782,0.2969 -1.2188,0.4453 -0.6406,0.1485 -1.3437,0.1485 -2.5,0 -3.8204,-1.6485 -1.3203,-1.6484 -1.3203,-4.7734 0,-3.125 1.3203,-4.7812 1.3204,-1.6563 3.8204,-1.6563 0.7031,0 1.3515,0.1563 0.6485,0.1562 1.211,0.4531 l 0,2.7187 q -0.625,-0.5781 -1.2188,-0.8515 -0.5937,-0.2735 -1.2187,-0.2735 -1.3438,0 -2.0313,1.0703 -0.6875,1.0704 -0.6875,3.1641 0,2.0938 0.6875,3.1641 0.6875,1.0703 2.0313,1.0703 0.625,0 1.2187,-0.2735 0.5938,-0.2734 1.2188,-0.8515 l 0,2.7187 z"
+ id="path60"
+ inkscape:connector-curvature="0" />
+ <text
+ font-size="12"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="56"
+ x="149.5"
+ y="36.015598"
+ id="text62"
+ style="font-size:12px;fill:#000000">HsrClient</text>
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="121.5"
+ x2="207.5"
+ y1="47"
+ y2="47"
+ id="line64" />
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="121.5"
+ x2="207.5"
+ y1="55"
+ y2="55"
+ id="line66" />
+ </g>
+ <g
+ id="g3148"
+ transform="translate(312.92827,361.80533)">
+ <rect
+ height="48"
+ style="fill:#fefece;stroke:#a80036;stroke-width:1.5"
+ width="93"
+ x="286.75"
+ y="15"
+ id="rect68" />
+ <ellipse
+ cx="301.75"
+ cy="31"
+ rx="11"
+ ry="11"
+ style="fill:#add1b2;stroke:#a80036;stroke-width:1"
+ id="ellipse70"
+ sodipodi:cx="301.75"
+ sodipodi:cy="31"
+ sodipodi:rx="11"
+ sodipodi:ry="11"
+ d="m 312.75,31 c 0,6.075132 -4.92487,11 -11,11 -6.07513,0 -11,-4.924868 -11,-11 0,-6.075132 4.92487,-11 11,-11 6.07513,0 11,4.924868 11,11 z" />
+ <path
+ d="m 304.7188,36.6406 q -0.5782,0.2969 -1.2188,0.4453 -0.6406,0.1485 -1.3437,0.1485 -2.5,0 -3.8204,-1.6485 -1.3203,-1.6484 -1.3203,-4.7734 0,-3.125 1.3203,-4.7812 1.3204,-1.6563 3.8204,-1.6563 0.7031,0 1.3515,0.1563 0.6485,0.1562 1.211,0.4531 l 0,2.7187 q -0.625,-0.5781 -1.2188,-0.8515 -0.5937,-0.2735 -1.2187,-0.2735 -1.3438,0 -2.0313,1.0703 -0.6875,1.0704 -0.6875,3.1641 0,2.0938 0.6875,3.1641 0.6875,1.0703 2.0313,1.0703 0.625,0 1.2187,-0.2735 0.5938,-0.2734 1.2188,-0.8515 l 0,2.7187 z"
+ id="path72"
+ inkscape:connector-curvature="0" />
+ <text
+ font-size="12"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="61"
+ x="315.75"
+ y="36.015598"
+ id="text74"
+ style="font-size:12px;fill:#000000">HsrServer</text>
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="287.75"
+ x2="378.75"
+ y1="47"
+ y2="47"
+ id="line76" />
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="287.75"
+ x2="378.75"
+ y1="55"
+ y2="55"
+ id="line78" />
+ </g>
+ <g
+ id="g3156"
+ transform="translate(477.06682,120.42231)">
+ <rect
+ height="86.4375"
+ style="fill:#fefece;stroke:#a80036;stroke-width:1.5"
+ width="316"
+ x="6.5"
+ y="130"
+ id="rect80" />
+ <ellipse
+ cx="124.75"
+ cy="146"
+ rx="11"
+ ry="11"
+ style="fill:#add1b2;stroke:#a80036;stroke-width:1"
+ id="ellipse82"
+ sodipodi:cx="124.75"
+ sodipodi:cy="146"
+ sodipodi:rx="11"
+ sodipodi:ry="11"
+ d="m 135.75,146 c 0,6.07513 -4.92487,11 -11,11 -6.07513,0 -11,-4.92487 -11,-11 0,-6.07513 4.92487,-11 11,-11 6.07513,0 11,4.92487 11,11 z" />
+ <path
+ d="m 127.7188,151.6406 q -0.5782,0.2969 -1.2188,0.4453 -0.6406,0.1485 -1.3437,0.1485 -2.5,0 -3.8204,-1.6485 -1.3203,-1.6484 -1.3203,-4.7734 0,-3.125 1.3203,-4.7812 1.3204,-1.6563 3.8204,-1.6563 0.7031,0 1.3515,0.1563 0.6485,0.1562 1.211,0.4531 l 0,2.7187 q -0.625,-0.5781 -1.2188,-0.8515 -0.5937,-0.2735 -1.2187,-0.2735 -1.3438,0 -2.0313,1.0703 -0.6875,1.0704 -0.6875,3.1641 0,2.0938 0.6875,3.1641 0.6875,1.0703 2.0313,1.0703 0.625,0 1.2187,-0.2735 0.5938,-0.2734 1.2188,-0.8515 l 0,2.7187 z"
+ id="path84"
+ inkscape:connector-curvature="0" />
+ <text
+ font-size="12"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="71"
+ x="145.25"
+ y="151.01559"
+ id="text86"
+ style="font-size:12px;fill:#000000">HsrAdapter</text>
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="7.5"
+ x2="321.5"
+ y1="162"
+ y2="162"
+ id="line88" />
+ <line
+ style="stroke:#a80036;stroke-width:1.5"
+ x1="7.5"
+ x2="321.5"
+ y1="170"
+ y2="170"
+ id="line90" />
+ <ellipse
+ cx="17.5"
+ cy="181.9063"
+ rx="3"
+ ry="3"
+ style="fill:#84be84;stroke:#038048;stroke-width:1"
+ id="ellipse92"
+ sodipodi:cx="17.5"
+ sodipodi:cy="181.9063"
+ sodipodi:rx="3"
+ sodipodi:ry="3"
+ d="m 20.5,181.9063 c 0,1.65685 -1.343146,3 -3,3 -1.656854,0 -3,-1.34315 -3,-3 0,-1.65686 1.343146,-3 3,-3 1.656854,0 3,1.34314 3,3 z" />
+ <text
+ font-size="11"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="188"
+ x="26.5"
+ y="185"
+ id="text94"
+ style="font-size:11px;fill:#000000">hsr_adapter_new() : HsrAdapter*</text>
+ <ellipse
+ cx="17.5"
+ cy="194.7188"
+ rx="3"
+ ry="3"
+ style="fill:#84be84;stroke:#038048;stroke-width:1"
+ id="ellipse96"
+ sodipodi:cx="17.5"
+ sodipodi:cy="194.7188"
+ sodipodi:rx="3"
+ sodipodi:ry="3"
+ d="m 20.5,194.7188 c 0,1.65685 -1.343146,3 -3,3 -1.656854,0 -3,-1.34315 -3,-3 0,-1.65686 1.343146,-3 3,-3 1.656854,0 3,1.34314 3,3 z" />
+ <text
+ font-size="11"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="266"
+ x="26.5"
+ y="197.8125"
+ id="text98"
+ style="font-size:11px;fill:#000000">hsr_adapter_handle_request(HsrAdapter *self,</text>
+ <text
+ font-size="11"
+ lengthAdjust="spacingAndGlyphs"
+ textLength="290"
+ x="26.5"
+ y="210.625"
+ id="text100"
+ style="font-size:11px;fill:#000000">GDataInputStream *gis, GDataOutputStream *gos)</text>
+ </g>
+ <g
+ id="g3199"
+ transform="matrix(0.9842874,-0.17657382,0.17657382,0.9842874,-888.6184,25.069898)">
+ <path
+ d="m 1146.0773,320.47353 c -14.256,18.818 -150.84167,198.0228 -163.50163,214.734"
+ style="fill:none;stroke:#a80036;stroke-width:1"
+ id="path102"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cc" />
+ <polygon
+ transform="translate(529.68833,234.78653)"
+ points="622.061,89.792 610.901,81.338 610.901,81.338 628.558,69.623 "
+ style="fill:none;stroke:#a80036;stroke-width:1"
+ id="polygon104" />
+ </g>
+ <g
+ id="g3203"
+ transform="translate(-702.1805,-183.54285)">
+ <path
+ d="m 1228.0413,318.19253 c 21.124,19.365 -0.3264,-0.95459 18.6436,16.43521"
+ style="fill:none;stroke:#a80036;stroke-width:1"
+ id="path106"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cc" />
+ <polygon
+ transform="translate(529.68833,234.78653)"
+ points="693.329,88.298 683.316,69.623 702.79,77.978 693.329,88.298 "
+ style="fill:none;stroke:#a80036;stroke-width:1"
+ id="polygon108" />
+ </g>
+ <path
+ style="fill:#ffffff;stroke:#000000;stroke-width:1.60000002;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker-end:url(#Arrow1Lend)"
+ d="m 235.07782,403.26021 360.24912,0"
+ id="path3207"
+ inkscape:connector-curvature="0" />
+ <path
+ style="fill:#ffffff;stroke:#000000;stroke-width:1.60000002;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker-end:url(#Arrow1Mend)"
+ d="m 128.9875,227.59583 -1.52648,149.24849"
+ id="path4421"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cc" />
+ <path
+ style="fill:#ffffff;stroke:#000000;stroke-width:1.60000002;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker-end:url(#Arrow1Mend)"
+ d="m 645.70077,376.80533 0,-39.94552"
+ id="path4609"
+ inkscape:connector-curvature="0" />
+ <path
+ style="fill:#ffffff;stroke:#000000;stroke-width:1.60000002;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker-end:url(#Arrow1Mend)"
+ d="m 643.41105,250.42232 0,-38.52492"
+ id="path4795"
+ inkscape:connector-curvature="0" />
+ <path
+ inkscape:connector-curvature="0"
+ id="path4981"
+ d="m 599.67827,417.04934 -360.24912,0"
+ style="fill:#ffffff;stroke:#000000;stroke-width:1.60000002;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker-end:url(#Arrow1Lend)" />
+ <path
+ sodipodi:type="arc"
+ style="fill:#ffffff;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
+ id="path4983"
+ sodipodi:cx="525.52502"
+ sodipodi:cy="506.63004"
+ sodipodi:rx="128.85146"
+ sodipodi:ry="49.921505"
+ d="m 654.37648,506.63004 a 128.85146,49.921505 0 1 1 -257.70291,0 128.85146,49.921505 0 1 1 257.70291,0 z"
+ transform="matrix(0.80000001,0,0,0.80000001,20.508293,3.3530815)" />
+ <text
+ xml:space="preserve"
+ style="font-size:17.60000038px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;text-anchor:start;fill:#000000;stroke:none;font-family:Liberation Sans;-inkscape-font-specification:Liberation Sans Bold"
+ x="344.32346"
+ y="413.32874"
+ id="text4989"><tspan
+ sodipodi:role="line"
+ id="tspan4991"
+ x="344.32346"
+ y="413.32874">Socket Communication</tspan></text>
+</svg>
View
28 src/basic-gio/socket-example/diagramm.uml
@@ -0,0 +1,28 @@
+@startuml
+skinparam shadowing false
+interface HsrIcalc
+
+HsrIcalc <|-- HsrProxy
+HsrIcalc <|-- HsrCalcImpl
+
+class HsrProxy {
+ + hsr_proxy_new() : HsrProxy*
+}
+
+class HsrCalcImpl {
+ + hsr_calc_impl_new () : HsrCalcImpl*
+}
+
+interface HsrIcalc {
+ + hsr_icalc_add(HsrIcalc *self, gint a, gint b) : gint
+}
+
+class HsrClient
+class HsrServer
+class HsrAdapter {
+ + hsr_adapter_new() : HsrAdapter*
+ + hsr_adapter_handle_request(HsrAdapter *self,
+ GDataInputStream *gis, GDataOutputStream *gos)
+}
+
+@enduml
View
60 src/basic-gio/socket-example/hsr-adapter.c
@@ -0,0 +1,60 @@
+#include "hsr-adapter.h"
+
+G_DEFINE_TYPE (HsrAdapter, hsr_adapter, G_TYPE_OBJECT)
+
+static void
+hsr_adapter_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (hsr_adapter_parent_class)->finalize (object);
+}
+
+static void
+hsr_adapter_class_init (HsrAdapterClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = hsr_adapter_finalize;
+}
+
+static void
+hsr_adapter_init (HsrAdapter *self)
+{
+}
+
+HsrAdapter *
+hsr_adapter_new ()
+{
+ return g_object_new (HSR_TYPE_ADAPTER, NULL);
+}
+
+void hsr_adapter_handle_request (HsrAdapter *self,
+ GDataInputStream *gis,
+ GDataOutputStream *gos)
+{
+ GError *err = NULL;
+ gint16 ergebnis;
+ HsrIcalc *server;
+
+ server = hsr_calc_impl_new();
+ gint32 a = g_data_input_stream_read_int32(gis, NULL, &err);
+ if ( err != NULL ) {
+ g_error("%s\n", err->message);
+ return;
+ }
+
+ gint32 b = g_data_input_stream_read_int32(gis, NULL, &err);
+ if ( err != NULL ) {
+ g_error("%s\n", err->message);
+ return;
+ }
+
+ ergebnis = hsr_icalc_add(server, a, b);
+
+ g_print("a: %d\nb: %d\nergebnis: %d\n", a, b, ergebnis);
+
+ g_data_output_stream_put_int32(gos, ergebnis, NULL, &err);
+ if ( err != NULL) {
+ g_error("%s\n", err->message);
+ return;
+ }
+}
View
38 src/basic-gio/socket-example/hsr-adapter.h
@@ -0,0 +1,38 @@
+#ifndef __HSR_ADAPTER_H__
+#define __HSR_ADAPTER_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+#include "hsr-calc-impl.h"
+
+G_BEGIN_DECLS
+
+#define HSR_TYPE_ADAPTER (hsr_adapter_get_type ())
+#define HSR_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HSR_TYPE_ADAPTER, HsrAdapter))
+#define HSR_ADAPTER_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HSR_TYPE_ADAPTER, HsrAdapter const))
+#define HSR_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HSR_TYPE_ADAPTER, HsrAdapterClass))
+#define HSR_IS_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HSR_TYPE_ADAPTER))
+#define HSR_IS_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HSR_TYPE_ADAPTER))
+#define HSR_ADAPTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HSR_TYPE_ADAPTER, HsrAdapterClass))
+
+typedef struct _HsrAdapter HsrAdapter;
+typedef struct _HsrAdapterClass HsrAdapterClass;
+
+struct _HsrAdapter
+{
+ GObject parent;
+
+};
+
+struct _HsrAdapterClass
+{
+ GObjectClass parent_class;
+};
+
+GType hsr_adapter_get_type (void) G_GNUC_CONST;
+HsrAdapter *hsr_adapter_new (void);
+void hsr_adapter_handle_request(HsrAdapter *self, GDataInputStream *gis, GDataOutputStream *gos);
+
+G_END_DECLS
+
+#endif /* __HSR_ADAPTER_H__ */
View
44 src/basic-gio/socket-example/hsr-calc-impl.c
@@ -0,0 +1,44 @@
+#include "hsr-calc-impl.h"
+
+gint
+hsr_calc_impl_add_real (HsrIcalc *self, gint a, gint b)
+{
+ return a + b;
+}
+
+void
+hsr_calc_impl_init_interface (HsrIcalcIface *iface)
+{
+ iface->add = hsr_calc_impl_add_real;
+}
+
+G_DEFINE_TYPE_WITH_CODE (HsrCalcImpl,
+ hsr_calc_impl,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE(HSR_TYPE_ICALC, hsr_calc_impl_init_interface))
+
+static void
+hsr_calc_impl_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (hsr_calc_impl_parent_class)->finalize (object);
+}
+
+static void
+hsr_calc_impl_class_init (HsrCalcImplClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = hsr_calc_impl_finalize;
+}
+
+static void
+hsr_calc_impl_init (HsrCalcImpl *self)
+{
+
+}
+
+HsrCalcImpl *
+hsr_calc_impl_new ()
+{
+ return g_object_new (HSR_TYPE_CALC_IMPL, NULL);
+}
View
36 src/basic-gio/socket-example/hsr-calc-impl.h
@@ -0,0 +1,36 @@
+#ifndef __HSR_CALC_IMPL_H__
+#define __HSR_CALC_IMPL_H__
+
+#include <glib-object.h>
+#include "hsr-icalc.h"
+
+G_BEGIN_DECLS
+
+#define HSR_TYPE_CALC_IMPL (hsr_calc_impl_get_type ())
+#define HSR_CALC_IMPL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HSR_TYPE_CALC_IMPL, HsrCalcImpl))
+#define HSR_CALC_IMPL_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HSR_TYPE_CALC_IMPL, HsrCalcImpl const))
+#define HSR_CALC_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HSR_TYPE_CALC_IMPL, HsrCalcImplClass))
+#define HSR_IS_CALC_IMPL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HSR_TYPE_CALC_IMPL))
+#define HSR_IS_CALC_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HSR_TYPE_CALC_IMPL))
+#define HSR_CALC_IMPL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HSR_TYPE_CALC_IMPL, HsrCalcImplClass))
+
+typedef struct _HsrCalcImpl HsrCalcImpl;
+typedef struct _HsrCalcImplClass HsrCalcImplClass;
+
+struct _HsrCalcImpl
+{
+ GObject parent;
+};
+
+struct _HsrCalcImplClass
+{
+ GObjectClass parent_class;
+};
+
+GType hsr_calc_impl_get_type (void) G_GNUC_CONST;
+HsrCalcImpl *hsr_calc_impl_new (void);
+
+
+G_END_DECLS
+
+#endif /* __HSR_CALC_IMPL_H__ */
View
26 src/basic-gio/socket-example/hsr-client.c
@@ -0,0 +1,26 @@
+
+#include <glib-object.h>
+#include "hsr-proxy.h"
+#include "hsr-icalc.h"
+#include <stdlib.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ g_type_init();
+
+ if ( argc < 3 ) {
+ g_print("Usage: %s a b\n", argv[0]);
+ return 0;
+ }
+
+ gint32 a = atoi(argv[1]);
+ gint32 b = atoi(argv[2]);
+
+ HsrIcalc *calc = HSR_ICALC(hsr_proxy_new());
+ gint32 ret = hsr_icalc_add(calc, a, b);
+ g_print("%d\n", ret);
+
+ return 0;
+}
View
51 src/basic-gio/socket-example/hsr-icalc.c
@@ -0,0 +1,51 @@
+#include "hsr-icalc.h"
+
+static void
+hsr_icalc_init (HsrIcalcIface *iface)
+{
+ static gboolean initialized = FALSE;
+
+ iface->add = hsr_icalc_add;
+
+ if (!initialized)
+ {
+ initialized = TRUE;
+ }
+}
+
+gint
+hsr_icalc_add (HsrIcalc *self, gint a, gint b)
+{
+ g_return_val_if_fail (HSR_ICALC (self), NULL);
+ return HSR_ICALC_GET_INTERFACE(self)->add(self, a, b);
+}
+
+GType
+hsr_icalc_get_type ()
+{
+ static GType hsr_icalc_type_id = 0;
+
+ if (!hsr_icalc_type_id)
+ {
+ static const GTypeInfo g_define_type_info =
+ {
+ sizeof (HsrIcalcIface),
+ (GBaseInitFunc) hsr_icalc_init,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
+
+ hsr_icalc_type_id =
+ g_type_register_static (G_TYPE_INTERFACE,
+ "HsrIcalc",
+ &g_define_type_info,
+ 0);
+ }
+
+ return hsr_icalc_type_id;
+}
View
29 src/basic-gio/socket-example/hsr-icalc.h
@@ -0,0 +1,29 @@
+#ifndef __HSR_ICALC_H__
+#define __HSR_ICALC_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define HSR_TYPE_ICALC (hsr_icalc_get_type ())
+#define HSR_ICALC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HSR_TYPE_ICALC, HsrIcalc))
+#define HSR_IS_ICALC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HSR_TYPE_ICALC))
+#define HSR_ICALC_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), HSR_TYPE_ICALC, HsrIcalcIface))
+
+typedef struct _HsrIcalc HsrIcalc;
+typedef struct _HsrIcalcIface HsrIcalcIface;
+
+struct _HsrIcalcIface
+{
+ GTypeInterface parent;
+
+ gint (*add) (HsrIcalc *self, gint a, gint b);
+};
+
+GType hsr_icalc_get_type (void) G_GNUC_CONST;
+
+gint hsr_icalc_add (HsrIcalc *self, gint a, gint b);
+
+G_END_DECLS
+
+#endif /* __HSR_ICALC_H__ */
View
90 src/basic-gio/socket-example/hsr-proxy.c
@@ -0,0 +1,90 @@
+#include "hsr-proxy.h"
+#include "hsr-icalc.h"
+
+#define HSR_PROXY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), HSR_TYPE_PROXY, HsrProxyPrivate))
+
+struct _HsrProxyPrivate
+{
+ //for testing purposes
+ gint tmp;
+};
+
+gint
+hsr_proxy_add_real (HsrIcalc *self, gint a, gint b)
+{
+ GSocketClient *client;
+ GSocketConnection *connection = NULL;
+ GError *err = NULL;
+
+ client = g_socket_client_new();
+ connection = g_socket_client_connect_to_host (client,
+ (gchar*)"localhost",
+ 6789,
+ NULL,
+ &err);
+ if ( err != NULL ) {
+ g_error("Something went wrong! %s\n", err->message);
+ return -1;
+ }
+
+ GDataInputStream *gis = g_data_input_stream_new(g_io_stream_get_input_stream(G_IO_STREAM(connection)));
+ GDataOutputStream *gos = g_data_output_stream_new(g_io_stream_get_output_stream(G_IO_STREAM(connection)));
+
+ g_data_output_stream_put_int32(gos, a, NULL, &err);
+ if ( err != NULL ) {
+ g_error ( "%s\n", err->message );
+ return 0;
+ }
+
+ g_data_output_stream_put_int32(gos, b, NULL, &err);
+ if ( err != NULL ) {
+ g_error ( "%s\n", err->message );
+ return 0;
+ }
+
+ gint32 ergebnis = g_data_input_stream_read_int32(gis, NULL, &err);
+ if ( err != NULL ) {
+ g_error ( "%s\n", err->message );
+ return 0;
+ }
+ return ergebnis;
+}
+
+void
+hsr_proxy_init_interface(HsrIcalcIface *self)
+{
+ self->add = (gint (*)(HsrIcalc*,gint,gint))hsr_proxy_add_real;
+}
+
+G_DEFINE_TYPE_WITH_CODE (HsrProxy,
+ hsr_proxy,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE( HSR_TYPE_ICALC, hsr_proxy_init_interface))
+
+static void
+hsr_proxy_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (hsr_proxy_parent_class)->finalize (object);
+}
+
+static void
+hsr_proxy_class_init (HsrProxyClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = hsr_proxy_finalize;
+
+ g_type_class_add_private (object_class, sizeof (HsrProxyPrivate));
+}
+
+static void
+hsr_proxy_init (HsrProxy *self)
+{
+ self->priv = HSR_PROXY_GET_PRIVATE (self);
+}
+
+HsrProxy *
+hsr_proxy_new ()
+{
+ return g_object_new (HSR_TYPE_PROXY, NULL);
+}
View
40 src/basic-gio/socket-example/hsr-proxy.h
@@ -0,0 +1,40 @@
+#ifndef __HSR_PROXY_H__
+#define __HSR_PROXY_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+
+G_BEGIN_DECLS
+
+#define HSR_TYPE_PROXY (hsr_proxy_get_type ())
+#define HSR_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HSR_TYPE_PROXY, HsrProxy))
+#define HSR_PROXY_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HSR_TYPE_PROXY, HsrProxy const))
+#define HSR_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HSR_TYPE_PROXY, HsrProxyClass))
+#define HSR_IS_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HSR_TYPE_PROXY))
+#define HSR_IS_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HSR_TYPE_PROXY))
+#define HSR_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HSR_TYPE_PROXY, HsrProxyClass))
+
+typedef struct _HsrProxy HsrProxy;
+typedef struct _HsrProxyClass HsrProxyClass;
+typedef struct _HsrProxyPrivate HsrProxyPrivate;
+
+struct _HsrProxy
+{
+ GObject parent;
+
+ HsrProxyPrivate *priv;
+};
+
+struct _HsrProxyClass
+{
+ GObjectClass parent_class;
+};
+
+GType hsr_proxy_get_type (void) G_GNUC_CONST;
+HsrProxy *hsr_proxy_new (void);
+
+
+G_END_DECLS
+
+#endif /* __HSR_PROXY_H__ */
View
50 src/basic-gio/socket-example/hsr-server.c
@@ -0,0 +1,50 @@
+
+#include <glib-object.h>
+#include <gio/gio.h>
+#include "hsr-adapter.h"
+
+gboolean
+connection_established(GSocketService *service,
+ GSocketConnection *connection,
+ GObject *source_object,
+ gpointer user_data) {
+ g_print("Connection established\n");
+ HsrAdapter *adapter = hsr_adapter_new();
+
+ GDataInputStream *gis = g_data_input_stream_new(g_io_stream_get_input_stream(G_IO_STREAM(connection)));
+ GDataOutputStream *gos = g_data_output_stream_new(g_io_stream_get_output_stream(G_IO_STREAM(connection)));
+
+ hsr_adapter_handle_request(adapter, gis, gos);
+
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GError *error = NULL;
+ GSocketService *service;
+
+ g_type_init();
+
+ service = g_socket_service_new();
+ /* Listening Details */
+ g_socket_listener_add_inet_port(G_SOCKET_LISTENER(service),
+ 6789,
+ NULL,
+ &error);
+ if ( error != NULL ) {
+ g_error("%s", error->message);
+ }
+
+ g_signal_connect (service,
+ "incoming",
+ G_CALLBACK(connection_established),
+ NULL);
+
+ g_socket_service_start(service);
+
+ GMainLoop* loop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(loop);
+ return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.