It is currently Sun Dec 08, 2019 10:10 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Winsock, PYTHON and ASCII [Resolved]
PostPosted: Wed Jun 26, 2019 2:01 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
Location: Lyon - France
Hello at all :D

I want talking with PYTHON on a Rasberry
For that i create a server on it and that works 8)

Code:
import socket

TCP_IP = '162.22.22.22'
TCP_PORT = 5005
BUFFER_SIZE = 20

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)
conn, addr = s.accept()
print ('Connection address:', addr)

while 1:

   data = conn.recv(BUFFER_SIZE)

   if data:
   
    print ("received data:", data)
    conn.send(data)  # echo

conn.close()
But when i use this nice code of BalrogSoft in unicode with 5.70, i have "Failed to connect" like result :| and with v4.51 in ASCII all are done :D
Code:
; http://www.purebasic.fr/english/viewtopic.php?p=67753#p67753

wsaData.WSADATA
iResult = WSAStartup_($101, @wsaData)

If iResult <> #NO_ERROR
 Debug "Error at WSAStartup()"
EndIf

; Create a socket for client
clientsocket = SOCKET_(#AF_INET, #SOCK_STREAM, #IPPROTO_TCP)

If clientsocket = #INVALID_SOCKET
 PrintN( "Error at socket(): " + Str(WSAGetLastError_()))
 WSACleanup_()
 End
EndIf

; Connect to a server.
*ptr = clientService.sockaddr_in

clientService\sin_family = #AF_INET
clientService\sin_addr = inet_addr_("162.22.22.22")
clientService\sin_port = htons_(5005)

If connect_(clientsocket, *Ptr, SizeOf(sockaddr_in)) = #SOCKET_ERROR

 Debug "Failed to connect"
 closesocket_(clientsocket)
 WSACleanup_()
 End

EndIf
Someone know where is the problem :cry:

Have a good day

_________________
ImageThe happiness is a road...
Not a destination


Last edited by Kwai chang caine on Wed Jun 26, 2019 6:52 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Winsock, PYTHON and ASCII
PostPosted: Wed Jun 26, 2019 2:33 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4448
Location: Germany
Why you need sockets on the client side :?:

Is this working?
Code:
InitNetwork()

Con = OpenNetworkConnection("162.22.22.22", 5005, #PB_Network_TCP|#PB_Network_IPv4, 3000)
If Con
  Debug "Connected"
  SendNetworkString(Con, "Hello World!", #PB_UTF8)
  CloseNetworkConnection(Con)
Else
  Debug "Connection failed"
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Winsock, PYTHON and ASCII
PostPosted: Wed Jun 26, 2019 6:50 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
Location: Lyon - France
Hello INFRATEC 8)

Master wrote:
Why you need sockets on the client side
Because KCC have the IQ of an Oyster :mrgreen:

I don't know Sockets are the same thing than usual TCP/IP PB functions :oops:
I have lost several hours with Ascii(), pointers, etc ... for nothing :|

I have run your code and PYTHON receive the "Hello World!" :shock:
I continue in this way :wink:

Thanks a lot for help me INFRATEC 8)
I wish you a very good night..not too hot (I talk of the weather obviously :lol:)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye