imagen

Fedicom Server with Go

16.Apr.2016 — Julio

Fedicom is a protocol designed to send orders from pharmacies to warehouses. The pharmacy transmits his order to the warehouse responds immediately with the products that can not be served and other relevant information, so it's a powerful utility.

I think the best way to learn a new programming language is with a project on mind, so my challenge to learn Go was to create a Fedicom Server. Además I've never worked with concurrency so It was a big challenge added for me.

I used my Server in DigitalOcean to implement my Go project.


Concurrency is not easy to understand, and I think I don´t get it yet, so I don´t dare to publish my code here. Always the first program you made when you are learning a new program language can produce laughs when It's seen from years after.

To test my code I needed a program to send Fedicom Orders, so I can test my server at the other side. Fortunately I made along years several programs to send Fedicom orders, in Delphi, Python and Flask.

send Fedicom order

At this moment the Fedicom Server can receive orders but It´s not coneccted to any ERP so I leave every order it receives in text files to be processed.

But perhaps I will implememt this for my company if I had time ...

==More information:==

++This is an order example:++

```  
0101201604142029071515            413241  
10101218            888888    870         00000903300       00000000  
102000000071213110001  
102000000012345670000  
10300000009923949002300003000  
102000000123412340005  
102000000000234120005  
102000000324423410005  
102000000003431450034  
102000004355445240005  
102000000012345450004  
102000000004525650065  
102000000452525250012  
102000004542525230012  
102000000055442430006  
102000000002454520005  
102000000045245450001  
102000001454655630001  
102000000045452540004  
102000002544254520002  
10500018000190000000  
0199  
```

++And this can be the response to the pharmacy:++

```  
0101201512091133071  
20101                         000000000000Pedido sin incidencias  
0199  
```

++This is the output I generate in the Fedicom Server to be procesed:++

```  
~/work/src/fedicom$ cat 20160414_204615_1515_1218_59575.txt  
[principal]  
usuario=1515  
cliente=1218  
tpedido=870  
pedido=888888 
dtopedido=33.00  
aplazamiento=090  
fechaenvio=00000000  

[articulos]  
0000000023412=5  
0000032rr2341=5  
00004355t4524=5  
0000000452565=65  
0000007121311=1  
0000045252525=12  
0000454252523=12  
0000005544243=6  
0000145465563=1  
0000001234545=4  
0000000343145=34  
0000004524545=1  
0000004545254=4  
0000012341234=5  
0000009923949=23;0;30.0  
0000000245452=5  
0000254425452=2  
0000001234567=0  
```

++I said I'm not going to publish my code yet, but in advance...++

```  
import (  
    "log"  
    "net"  
    "fedicom"  
)  

func main() {  
    // Listen on TCP port 1111  
    l, err := net.Listen("tcp", ":1111")  
    if err != nil {  
        log.Fatal(err)  
    }  
    defer l.Close()  
    for {  
        // Waiting for connections.  
        conn, err := l.Accept()  
        if err != nil {  
            log.Fatal(err)  
        }  
        // multiple orders may be served concurrently.  
        go fedicom.Fedlee(conn)  
    }  
}
```

Tags: fedicom, Go

Comments? Tweet