Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
69
Task/Sockets/FreeBASIC/sockets.basic
Normal file
69
Task/Sockets/FreeBASIC/sockets.basic
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
' We import the windows sockets library
|
||||
#Include Once "windows.bi"
|
||||
#Include Once "win/winsock.bi"
|
||||
|
||||
#include "fbgfx.bi"
|
||||
|
||||
#define NET_BUFLEN 1024
|
||||
|
||||
'--- SENDER ---
|
||||
|
||||
Dim As WSADATA wsaData
|
||||
|
||||
Dim As SOCKET sendSocket
|
||||
Dim As sockaddr_in recvAddr
|
||||
Dim As Integer port = 256
|
||||
Dim As Ubyte sendBuf(NET_BUFLEN-1)
|
||||
Dim As Integer bufLen = NET_BUFLEN
|
||||
Dim As Integer iResult
|
||||
Dim As String message = "hello socket world"
|
||||
|
||||
' We copy the message to the buffer
|
||||
For i As Ubyte = 1 To Len(message)
|
||||
sendBuf(i-1) = Cbyte(Asc(Mid(message, i, 1)))
|
||||
Next
|
||||
|
||||
' We update bufLen to be the length of the message
|
||||
bufLen = Len(message)
|
||||
|
||||
' We initialize Winsock
|
||||
If (WSAStartup(MAKEWORD(2,2), @wsaData) <> 0) Then
|
||||
Beep: Print "Error: Winsock init"
|
||||
Sleep
|
||||
End
|
||||
End If
|
||||
|
||||
' We create the socket
|
||||
sendSocket = socket_(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
|
||||
If sendSocket = INVALID_SOCKET Then
|
||||
Beep: Print "Error: Net socket"
|
||||
WSACleanup()
|
||||
Sleep
|
||||
End
|
||||
End If
|
||||
|
||||
' We configure the server structure
|
||||
recvAddr.sin_family = AF_INET
|
||||
recvAddr.sin_port = htons(256)
|
||||
recvAddr.sin_addr.s_addr = inet_addr("127.0.0.1")
|
||||
|
||||
' We send the message
|
||||
Print "Trying: Net send"
|
||||
iResult = sendto(sendSocket, @sendBuf(0), bufLen, 0, Cptr(sockaddr Ptr, @recvAddr), Sizeof(recvAddr))
|
||||
If (iResult = SOCKET_ERROR) Then
|
||||
Beep: Print "Error: Net send"
|
||||
closesocket(sendSocket)
|
||||
WSACleanup()
|
||||
Sleep
|
||||
End
|
||||
Else
|
||||
Print "number of bytes send:"; iResult
|
||||
End If
|
||||
|
||||
iResult = closeSocket(sendSocket)
|
||||
If (iResult < 0) Then
|
||||
Beep: Print "Error: Close socket"
|
||||
End If
|
||||
|
||||
'closesocket(sock)
|
||||
WSACleanup()
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
s = newJava["java.net.Socket", ["localhost", 250]]
|
||||
s = newJava["java.net.Socket", ["localhost", 256]]
|
||||
w = new Writer[s.getOutputStream[]]
|
||||
w.println["hello socket world"]
|
||||
w.close[]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue