Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: RFComm golang server/client #23941

Closed
Basekeet opened this issue Feb 20, 2018 · 2 comments
Closed

x/sys/unix: RFComm golang server/client #23941

Basekeet opened this issue Feb 20, 2018 · 2 comments

Comments

@Basekeet
Copy link

Go version - 1.10
OS - linux
Arch - arm

I tried to use package unix but having some problem

I hope you'll help me to create a RFComm server and client.

Also I have python code which must work similarly.
Server:


import socket
import json

hostMACaddress = '00:17:e9:f6:89:9e'
port = 3
backlog = 1
size = 1024

def waitValue(val):
  s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
  s.bind((hostMACaddress, port))
  s.listen(backlog)
  print("Starting server")

  try:
    client, address = s.accept()
    print("Connected")
    
    while True:
      data = client.recv(size)
      
      if data:
        data = data.decode('UTF-8')
        #unwrapped = json.loads(data)
        #print(unwrapped)
        print("Client data:", data)
      
        myData = val
        
        print("My data:", myData)
        
        client.send(bytes(str(myData), 'UTF-8'))
      else:
        print("Bad data")
        
  except:
    print("Closing server")
    client.close()
    s.close()

Client:

import socket
import json

value = 111
print('My value: ' + str(value))

serverMAC = '00:17:e9:f6:89:9e'
port = 3

def sendVal(val):
    sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
    sock.connect((serverMAC, port))

    data = json.dumps(val)
    sock.send(bytes(data, 'UTF-8'))

    taken = sock.recv(1024)
    print(taken.decode('UTF-8'))
    sock.close()

Thanks.

@cznic
Copy link
Contributor

cznic commented Feb 20, 2018

C/P from other issue:

Unlike some other projects, we don't use the issue tracker for discussion. We only use it for bug reports. Please take any discussion to a forum; see https://golang.org/wiki/Questions. Thanks.

@ALTree
Copy link
Member

ALTree commented Feb 20, 2018

Yeah this is a not a Go bug report. I also have a suggestion. You write

I tried to use package unix but having some problem

when you post your question in one of the places cznic linked above, include the Go code you wrote (even if it doesn't work) and explain what problems you encountered. It's much better than just asking someone to port your Python code to Go from scratch.

@ALTree ALTree closed this as completed Feb 20, 2018
@mikioh mikioh changed the title RFComm golang server/client x/sys/unix: RFComm golang server/client Feb 21, 2018
@golang golang locked and limited conversation to collaborators Feb 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants