Darkover

Darkover

Angelic
Jul 29, 2021
4,431
trying to do some coding even tho i've got a brain injury its hard to remember everything going to code a simple chat program with a server and clients to send messages for windows 10
this is what i've managed to achive so far using chat gpt in the euphoria programming lanaguage

i used chat gpt to create a circular buffer for me and built from there

circular buffer
C:
-- Define the size of the circular buffer
-- Define the size of the circular buffer
constant BUFFER_SIZE = 100


-- Define the circular buffer and the read and write indices
sequence buffer 
buffer= repeat(0, BUFFER_SIZE)
integer read_index,write_index,read_size
read_index=0
 write_index = 0
read_size=0

-- Function to write a packet to the circular buffer
global procedure write_packet(sequence packet)
  -- Check if there is enough space in the buffer for the packet
  if length(packet) > BUFFER_SIZE - write_index then
    -- Not enough space, move the write index to the beginning of the buffer
    read_size-= write_index-read_index
    write_index = 0
  end if
  
  -- Copy the packet to the buffer
  for i = 1 to length(packet) do
    buffer[write_index + i] = packet[i]
    
  end for
  
  -- Update the write index
  write_index += length(packet)
  read_size+=length(packet)
end procedure

-- Function to write a packet to the circular buffer
global procedure write_byte(integer packet)
  -- Check if there is enough space in the buffer for the packet
  if 1 > BUFFER_SIZE - write_index then
    -- Not enough space, move the write index to the beginning of the buffer
    read_size-= write_index-read_index
    write_index = 0
  end if
  
  -- Copy the packet to the buffer
    buffer[write_index +1] = packet
    
  
  -- Update the write index
  write_index += 1
  read_size+=1
end procedure


global procedure writeutf(sequence v)
   sequence s
   s=int_to_bytes(length(v))
   write_packet(s[2]&s[1]&v)
end procedure

global procedure writeint(atom v)
sequence s
   s=int_to_bytes(v)
   write_packet(s[4]&s[3]&s[2]&s[1])
end procedure

global procedure writebool(integer b)
  write_packet(b)
end procedure

global procedure writeshort( atom v)
   sequence s
   s=int_to_bytes(v)
  write_packet(s[2]&s[1])
end procedure

global procedure writebyte(integer v)
   write_byte(v)
end procedure



-- Function to read a packet from the circular buffer
global function read_packet(integer size)

sequence packet
packet = {}
  -- Check if there is enough data in the buffer to read a packet
  if size > BUFFER_SIZE - read_index then
    -- Not enough data, move the read index to the beginning of the buffer
    read_index = 0
  end if
  
  -- Read the packet from the buffer
  
  for i = 1 to size do
   packet&=  buffer[read_index + i]
   if read_index+i> BUFFER_SIZE then
    -- Not enough data, move the read index to the beginning of the buffer
    read_index = 0
  end if
  end for
  
  -- Update the read index
  read_index += size
  read_size-=size
  
  return packet
end function

global function read_byte()


  -- Check if there is enough data in the buffer to read a packet
  if 1 > BUFFER_SIZE - read_index then
    -- Not enough data, move the read index to the beginning of the buffer
    read_index = 0
  end if
  
  -- Read the packet from the buffer
  
 
  
   if read_index+1> BUFFER_SIZE then
    -- Not enough data, move the read index to the beginning of the buffer
    read_index = 0
  end if
  
  -- Update the read index
  read_index += 1
  read_size-=1
  
  return buffer[read_index ]
end function


global function input_stream_readutf()
  integer len
  len=bytes_to_int( reverse(read_packet(2))&{0,0} )
  
  return read_packet(len)
end function

global function input_stream_readint()
  atom v
  v=bytes_to_int( reverse(read_packet(4)) )
 
  return v
end function

global function input_stream_readfloat()
  atom v
  v=float32_to_atom( reverse(read_packet(4)) )
 
  return v
end function

global function input_stream_readshort()
atom v
  v=bytes_to_int( reverse(read_packet(2))&{0,0} )
  return v
end function


global function input_stream_readbyte()
 
  return read_byte()
end function

global function input_stream_readbool()
  
  return and_bits(read_packet(1),#1)
end function

global function buffer_size()
  return read_size
end function




server code
C:
--  code generated by Win32Lib IDE v0.21.1 Build Sept-29-2006

constant TheProgramType="exw"
 
include Win32Lib.ew
without warning

--------------------------------------------------------------------------------
--  Window Window1
constant Window1 = createEx( Window, "server", 0, Default, Default, 400, 300, 0, 0 )
constant PushButton2 = createEx( PushButton, "PushButton2", Window1, 96, 136, 88, 28, 0, 0 )
---------------------------------------------------------
--------------------------------------------------------------------------------
include SrvSckIP.ew
include buffer.ew
atom hWndMainWindow,Server_sock
global constant SM_ASYNC = #FFFF

integer hello_packet

hello_packet =1

sequence client_list
client_list={}


writeutf("testing")
writeint(1234)
writeshort(999)
writebyte(245)
writebyte(246)

puts(1, input_stream_readutf())
puts(1, sprint(input_stream_readint()))
puts(1, sprint(input_stream_readshort()))
puts(1, sprint(input_stream_readbyte()))
puts(1, sprint(input_stream_readbyte()))
puts(1,"buffer size \n")
?buffer_size()



procedure processServerMessage(atom hWnd, atom arg1, atom arg2)
  atom      index, newsock
  integer   action, sock, iwork
  object    owork,junk
  sequence  newIP,swork,rx,tx
  sequence  data,temp

  action = lo_word(arg2)
  sock = arg1
  puts(1,"process server messafe\n")
  if action=FD_ACCEPT then
    puts(1,"SERVER ACCEPT\n")
    newsock = WsockAccept(Server_sock)
    client_list&=newsock
   elsif action=FD_CONNECT then
    puts(1,"SERVER connect\n")


  elsif action = FD_WRITE then
    puts(1,"fd-write")
        ?sock
    ?WsockSendData(sock,repeat(1,1024))

  elsif action = FD_READ then
    puts(1,"server packet recived\n")
    rx = ""
    owork = WsockReadData_1024(sock,1024)

    while sequence(owork) do
      rx = rx & owork
      owork = WsockReadData_1024(sock,1024)

    end while
    if length(rx) > 0 then


    end if
  elsif action = FD_CLOSE then
     puts(1,"server socket closed\n")
     for i=1 to length(client_list) do
       
     end for
     WsockCloseSocket(sock)
  end if
end procedure


--------------------------------------------------------------------------------
procedure Window1_onEvent (integer self, integer event, sequence params)--params is ( int iMsg, atom wParm, atom lParm )
  if params[1] = SM_ASYNC then
    processServerMessage(hWndMainWindow,params[2],params[3])
  end if
end procedure
setHandler( Window1, w32HEvent, routine_id("Window1_onEvent"))
--------------------------------------------------------------------------------
procedure Window1_onOpen (integer self, integer event, sequence params)--params is ()
  integer iwork, port
  sequence swork,ip
  atom Server

  port = 2050

  iwork = WsockInit()
  if iwork = -1 then -- WinSock failed
    iwork = message_box("WSockInit() failed!","Error",MB_TASKMODAL + MB_ICONSTOP + MB_OK)
    abort(99)
  end if


  hWndMainWindow = getHandle(Window1)

  Server_sock = WsockListenAsync(port, hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_ACCEPT,FD_CLOSE,FD_CONNECT}))

  if Server_sock = SOCKET_ERROR then  -- WinSock failed
    iwork = message_box("WsockListenAsync() failed!","Error",MB_TASKMODAL+MB_ICONSTOP+MB_OK)
    abort(99)
  end if
end procedure
setHandler( Window1, w32HOpen, routine_id("Window1_onOpen"))
--------------------------------------------------------------------------------
procedure PushButton2_onClick (integer self, integer event, sequence params)--params is ()
  for i=1 to length(client_list) do
       ?WsockSendData(client_list[i],repeat(1,1024))
    ?client_list[i]
  end for

end procedure
setHandler( PushButton2, w32HClick, routine_id("PushButton2_onClick"))


WinMain( Window1,Normal )
--this program has 133 lines without including this line. If there is a discrepancy please send this file zipped to Judith.

client code


C:
--  code generated by Win32Lib IDE v0.21.1 Build Sept-29-2006

constant TheProgramType="exw"
 
include Win32Lib.ew
without warning

--------------------------------------------------------------------------------
--  Window Window1
constant Window1 = createEx( Window, "client", 0, Default, Default, 400, 300, 0, 0 )
constant PushButton2 = createEx( PushButton, "PushButton2", Window1, 92, 124, 88, 28, 0, 0 )
constant PushButton3 = createEx( PushButton, "PushButton3", Window1, 244, 136, 88, 28, 0, 0 )
---------------------------------------------------------
--------------------------------------------------------------------------------
include SrvSckIP.ew
include buffer.ew
atom hWndMainWindow,Server_sock
global constant SM_ASYNC = #FFFF

constant port=2050
constant ip="127.0.0.1"



integer hello_packet

hello_packet =1


procedure connect_to_server()
    integer iwork
  sequence swork

  iwork = WsockInit()
  if iwork = -1 then -- WinSock failed
    iwork = message_box("WSockInit() failed!","Error",MB_TASKMODAL + MB_ICONSTOP + MB_OK)
    abort(99)
  end if

  hWndMainWindow = getHandle(Window1)


  Server_sock=Wsock_new(ip, port , hWndMainWindow, SM_ASYNC,or_all({FD_READ,FD_CLOSE,FD_CONNECT}))
end procedure


procedure processServerMessage(atom hWnd, atom arg1, atom arg2)
  atom      index, newsock
  integer   action, sock, iwork
  object    owork,junk
  sequence  newIP,swork,rx,tx
  sequence  data,temp

  action = lo_word(arg2)
  sock = arg1

  if action=FD_CONNECT then

   puts(1,"client connected\n")
   ?sock
   ?Server_sock
  elsif action = FD_READ then
   puts(1,"packet recived\n")
    rx = ""
    owork = WsockReadData_1024(sock,1024)

    while sequence(owork) do
      rx = rx & owork
      owork = WsockReadData_1024(sock,1024)

    end while
    if length(rx) > 0 then


    end if
  elsif action = FD_CLOSE then
     puts(1,"client closed\n")
     WsockCloseSocket(sock)
  end if
end procedure


--------------------------------------------------------------------------------
procedure Window1_onEvent (integer self, integer event, sequence params)--params is ( int iMsg, atom wParm, atom lParm )
  if params[1] = SM_ASYNC then
    processServerMessage(hWndMainWindow,params[2],params[3])
  end if
end procedure
setHandler( Window1, w32HEvent, routine_id("Window1_onEvent"))
--------------------------------------------------------------------------------
procedure PushButton2_onClick (integer self, integer event, sequence params)--params is ()
  connect_to_server()
end procedure
setHandler( PushButton2, w32HClick, routine_id("PushButton2_onClick"))
--------------------------------------------------------------------------------
procedure PushButton3_onClick (integer self, integer event, sequence params)--params is ()
  ?WsockSendData(Server_sock,repeat(1,1024))
  ?Server_sock
end procedure
setHandler( PushButton3, w32HClick, routine_id("PushButton3_onClick"))


WinMain( Window1,Normal )
--this program has 103 lines without including this line. If there is a discrepancy please send this file zipped to Judith.
 
Last edited:
  • Like
Reactions: Maudlin
whatevs

whatevs

Mining for copium in the weirdest places.
Jan 15, 2022
2,914
Is this going to be deployed anywhere? Most people here are not programmers and would just want to try your site/program.

ChatGPT has so far sucked for me for Dart, it's only proven useful for dumb but repetitive tasks. Which is good as I want to keep my job for now. I have a coworker that has had better luck asking for very specific questions and giving it enough context, it seems it's good for that also. I still prefer StackOverflow.
 
Last edited:
Darkover

Darkover

Angelic
Jul 29, 2021
4,431
Is this going to be deployed anywhere? Most people here are not programmers and would just want to try your site/program.
probably not going to host it anywhere, i could get a domain name and vps for cheap
but i was thinking of creating a peer to peer network for chat so the client just connects to the server to get a list of nodes
and then connects to the other client directly when sending a message would want to send pictures as well
chatgpt is good for learning how computers all work Arithmetic logic unit float point unit ect
also linear interpolation in the c programming language for movement 360 degress moving between two point smothly



The IEEE 754 standard is a widely used representation for floating-point numbers. It was developed by the Institute of Electrical and Electronics Engineers (IEEE) in the 1980s, and it has since become the most widely used standard for floating-point arithmetic.

In the IEEE 754 standard, a floating-point number is made up of three parts: a sign bit, an exponent, and a significand. The sign bit is a single bit that indicates whether the number is positive or negative. The exponent is an integer that indicates the power of 10 by which the significand is multiplied. The significand is a fractional number that represents the significant digits of the number.

The number of bits used to represent each of these parts determines the precision and range of the numbers that can be represented. For example, the single precision format uses 32 bits and can represent numbers with about 7 digits of precision, while the double precision format uses 64 bits and can represent numbers with about 16 digits of precision.

The IEEE 754 standard also defines a set of rules for how floating-point numbers are to be handled in arithmetic operations, such as addition, subtraction, multiplication, and division. These rules ensure that the results of floating-point operations are consistent and accurate across different computer systems.
it good but not brilant


The significand, also known as the mantissa, is the fractional part of a floating-point number. In the IEEE 754 standard, which is a widely used representation for floating-point numbers, the significand is a fractional number that represents the significant digits of the number.

For example, in the number 3.14159, the significand is 0.14159. In the number -12.34, the significand is 0.34.

The significand is combined with an exponent, which is an integer indicating the power of 10 by which the significand is multiplied, to represent the full value of the floating-point number. For example, in the number 3.14159, the significand is 0.14159 and the exponent is -2, so the full value of the number is 3.14159 * 10^(-2) = 0.0314159.

The precision of a floating-point number is determined by the number of bits used to represent the significand. The more bits that are used, the more digits of precision the number can represent.

Floating-point addition is the process of adding two numbers that have decimal points. It is performed by the floating-point unit (FPU) on the CPU (Central Processing Unit) using specialized hardware circuits and algorithms.

The steps involved in floating-point addition are as follows:

  1. Align the decimal points of the two operands by shifting the significand (the fractional part of the number) of one of the operands to the right until the two decimal points are aligned.
  2. Add the two significands together, and adjust the exponent (the power of 10 by which the significand is multiplied) if necessary to account for any carrying over in the addition.
  3. Normalize the result by shifting the significand to the left until there is no leading zeros and the decimal point is in the correct position.
  4. Return the result.
For example, to add the numbers 0.1 and 0.2, the FPU would align the decimal points by shifting the significand of 0.1 to the right, resulting in 0.10 and 0.2. It would then add the significands 0.10 and 0.2 to get 0.30, and normalize the result to 0.3. The final result would be 0.3.
 
Last edited:
whatevs

whatevs

Mining for copium in the weirdest places.
Jan 15, 2022
2,914
I'm not into low level programming, knowing and applying SOLID principles or clean architecture is already hard work for me.

Most of the stuff about how computers work is useless for intermediate programming where you use a framework for apps, websites, etc.

It's cool that there are people into low level programming though, as that is needed for the technologies that sit above it.
 
whatevs

whatevs

Mining for copium in the weirdest places.
Jan 15, 2022
2,914
This is the kind of stuff I like or tend to do. This is a function to divide into a custom number of pages a book, based on the min and max number of characters. This took me like 6h.

1673040306181
 

Similar threads

Darkover
Replies
1
Views
83
Offtopic
Darkover
Darkover
GuessWhosBack
Replies
6
Views
651
Recovery
hellworldprincess
hellworldprincess
Darkover
Replies
1
Views
181
Offtopic
Forever Sleep
F
Darkover
Replies
2
Views
218
Offtopic
somenone
S
Darkover
Replies
0
Views
266
Offtopic
Darkover
Darkover