News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Joseman

CPChessNet [developing]

Started by Joseman, 00:36, 03 March 18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Joseman


Here it is!!

CPChessNET 1.6b

http://www.cpcwiki.eu/forum/programming/cpchessnet-(developing)/?action=dlattach;attach=25021

[old]
Hi

I have been working on a Chess program for the CPC.

The idea is to use the M4 to connect 2 cpc via tcp/ip and the people can play chess all over the world!

At this point I can start to code the Net part of the program, the problem is that i have no idea.

The game doesn't use firmware, doesn't use ints, only pure (sloppy) asm :)

@Duke can you help me with the m4 and the process to access the hardware to make a connection between 2 cpcs?

I never coded any client/server tcp/ip program, i suspect that with the M4 is easy... how can i start?

thankyou!

1 pic of the program:


Duke

Good idea :)

Quote from: Joseman on 00:36, 03 March 18
@Duke can you help me with the m4 and the process to access the hardware to make a connection between 2 cpcs?

I never coded any client/server tcp/ip program, i suspect that with the M4 is easy... how can i start?

Start by playing with the samples I made at:
https://github.com/M4Duke/M4examples

There's "tcp.s" which is a tcp/ip client. Run this on one CPC.
On another CPC run "tcpserv.s" which is a tcp/ip server.

This is the basics you need to transfer moves from one CPC to another. And probably the simplest method.
In your chess game, you would have to select if you want to be "host" (server) or join a server (be client).

You can also use the PC server (main.c) for some tests to understanding how it works. Advantage with that is you can install the awesome Wireshark program and monitor all packets closely.

Anyway have a look and I will be glad to help if there's anything.

Joseman

#2
hi @Duke

Thanks for the help!

seems very easy to make it, i'm trying it

one question,  when you read the buffer of the m4, how can you know the end of the buffer on every command?

thanks!!

Duke

Quote from: Joseman on 14:41, 03 March 18
one question,  when you read the buffer of the m4, how can you know the end of the buffer on every command?

(socket*16)+2    received: (2 bytes)    - data received in internal buffer (ready to get with C_NETRECV)

Once there is nothing in the incoming buffer (00 00)

Gryzor

You're doing a chess game? Respect.

Joseman

Quote from: Gryzor on 19:01, 03 March 18
You're doing a chess game? Respect.

Well... i'm doing (trying to do) a NETchess, no computer AI, "only" piece moves, a little chat and move the board information between the 2 cpc's :D


GUNHED

Oh, interesting project! I'm not really updated what exactly is possible with the M4 and SymbOS. But maybe it's the best idea just to use all the Wifi-/Net-stuff from SymbOS instead of doing every thing new? - IIRC SymbOS 3 provides quite so great routines for Wifi-Connection.  :)


Yes, of course it's fun to code something by oneself!  :) :) :)
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

Joseman

Quote from: GUNHED on 12:55, 04 March 18
Oh, interesting project! I'm not really updated what exactly is possible with the M4 and SymbOS. But maybe it's the best idea just to use all the Wifi-/Net-stuff from SymbOS instead of doing every thing new? - IIRC SymbOS 3 provides quite so great routines for Wifi-Connection.  :)


Yes, of course it's fun to code something by oneself!  :) :) :)

Yes, i've been waiting ages for the IDE program enviroment for symbos, years later, i've decided to code on plain asm :)

Joseman

@Duke

C_NETBIND is giving me ramdom #FC code error (in my program), your program seems to connect right

sometimes it works some time not...

what can i be doing wrong?

thanks!

Duke

Quote from: Joseman on 14:18, 04 March 18
@Duke

C_NETBIND is giving me ramdom #FC code error (in my program), your program seems to connect right

sometimes it works some time not...

what can i be doing wrong?

The error codes are:
-1      Out of memory error.   
-2      Buffer error.           
-3      Timeout                 
-4      Routing problem.       
-5      Operation in progress   
-6      Illegal value.         
-7      Operation would block. 
-8      Address in use.         
-9      Already connected.     
-10     Connection aborted.     
-11     Connection reset.       
-12     Connection closed.     
-13     Not connected.         
-14     Illegal argument.       

So you get -4, routing problem!

Don't know what you do wrong, without seeing the code.

Remember to always close a socket, even if you have an error or you will have to power off/on M4 to free it, maybe that's it ?

GUNHED

Also Shining did some work with the WiFi for his great defence game, which can save highscores in the network IIRC. Maybe he can give some hints. Anyway good luck with the project.  :)
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

Joseman

@Duke

finally i did it!

i have 2 cpc connected (or so they say  ;D )

The thing is... they don't connect always

the cpc server seems to display my connected msg every now and then... but the cpc client always display my connected msg (even if the cpc server don't display it!)

i suspect that the cpc server get stuck on :

cp    4    ; incoming connection in progress?
jp z,wait_client

i say "suspect" because is a PAIN to code totally blind when you have to debug the m4 code  :laugh:

what do you think is the problem?

when i have to close socket?

thankyou!
 


Duke

#12
Quote from: Joseman on 22:22, 04 March 18
@Duke

finally i did it!

i have 2 cpc connected (or so they say  ;D )
Cool  8)
Quote
The thing is... they don't connect always
Is it the same when using my examples (tcp client & tcp server)?

Quote
the cpc server seems to display my connected msg every now and then... but the cpc client always display my connected msg (even if the cpc server don't display it!)

i suspect that the cpc server get stuck on :

cp    4    ; incoming connection in progress?
jp z,wait_client

i say "suspect" because is a PAIN to code totally blind when you have to debug the m4 code  :laugh:
At this point, it may be a good idea to use the pc tcp server example for testing, it's easy throw in debug output there to make sure everything is going is it should from the client side.
Quote
what do you think is the problem?
No idea with the current information, sorry :)
Quote
when i have to close socket?
When you are done using a socket and the connection is no longer needed or an error occurred and you want to create a new socket.
There is only 4 sockets, so if you run the same test on cpc without closing the sockets (or power cycle) you will run out.


Btw. to compile the PC tcp server on windows, just install MinGW and copy main.c + makefile into a dir and type make

Joseman

OMG i made it!!!

it was blood, sweat, and tears programming the M4 almost blindly!!

But i made it, client/server and the first transmisions (their nicks!).

is the first time that i start to believe that cpchessnet can be made!

pic:







Joseman

Hi @Duke

One question, i have a little chat on the game, if i send a msg from the client to the server, but the server is checking the game parts, the client will wait forever for the server to receive the msg...

how can i tell the M4 to send the msg, and just continue with his things on the client side?

i suspect that this part of the code is the key:


wait_send:    ld    a,(ix)
            cp    2            ; send in progress?
            jr    z,wait_send    ; Could do other stuff here!
            cp    0
            call    nz,error_envio   


i don't want to "wait_send" just put the message out and continue...

maybe i need to do a variable called "message_pending" and if message_pending=1 then retry the send ony 1 time? make my things, retry another time...if message send then  "message_pending=0"

i'm learning for the first time client/server programming and i'm a little lost!

thankyou!!






Duke

Quote from: Joseman on 21:52, 05 March 18


i suspect that this part of the code is the key:


wait_send:    ld    a,(ix)
            cp    2            ; send in progress?
            jr    z,wait_send    ; Could do other stuff here!
            cp    0
            call    nz,error_envio   


i don't want to "wait_send" just put the message out and continue...

You don't need to wait around for the message being sent, but you must just make sure it is sent before sending the next message.

Joseman

Hi again @Duke

I think that some questions are more related to client/server aplications, hope this thread can be useful for another people  :laugh:

For example:

When you stablish a socket, do this socket need to be "renewed" some times? or keep alive? or when you stablish the socket, it remains forever stablished?

and this commands: cmdbind, cmdlisten, cmdaccept. they are sent to the M4 only one time? (stablish socket part).

I mean, first stablish socket, ok then later in the code, after do "chess things", at the end of the loop, only need to do wait_client and wait_recv, or only wait_recv. Or i have to do again cmdbind, cmdlisten and cmdaccept?.

Sorry for so many questions, it think i'm near to understand all, but is just that now it doesn't work correctly

Thankyou!

Duke


You do not need to renew a socket, unless there is a disconnection. In that case you will need to close the socket and create it again.
On server side you *can* get away with keeping the socket and wait for a new incoming connection, but it may be safer to close the socket and re-do it all.

In your chess loop, you do not need to wait for anything unless you see something in the buffer.  Anyting in buffer ? if yes, wait recv, if no continue game loop.


Joseman

Hi again again @Duke

I think i have sorted the problem...

when i can interchange nicks, before it the socket is  in status 4 (wait incoming)

but, when i enter the game, and try to receive a chat message from the client, the socket is status 0 (inactive)

how can i put the socket in wait incoming?

Duke

Quote from: Joseman on 20:46, 06 March 18
when i can interchange nicks, before it the socket is  in status 4 (wait incoming)

but, when i enter the game, and try to receive a chat message from the client, the socket is status 0 (inactive)

how can i put the socket in wait incoming?
"wait incoming" is for establishing a connection to the host, after connection established you will only need to check if there is something for you:
(socket*16)+2    received: (2 bytes)    - data received in internal buffer (ready to get with C_NETRECV)
Check this in the socket status, if there is anything, use C_NETRECV.


Joseman

I don't even bother to say how many hours took me to do this... finally there is a real chat client -> server working on cpchessnet!




robcfg

Awesome!  8)


When will be able to play it?

Joseman

Quote from: robcfg on 10:44, 07 March 18
Awesome!  8)


When will be able to play it?

Well, the net part took me days... the chess part was stalled, only 3 pieces knows their moves  :laugh:

next i will try to send the board to the client (after white move) and repaint the board on the client...

Joseman

Hi (again) @Duke

Right know i have a chat between the 2 cpc's

what i do is:

key t --> open chat ---> enter message --> send message to the other cpc --> update the chat_buffer on local  with local message -->repaint chat

on the other side: wait for a message --> yes? ---> move message to chat_buffer on local --> repaint chat

The thing is... what about if the other side don't receive the message (by a net error) but i update my local chat?

on a local net, there isn't virtually errors, and the chat works very well... but on Inet.. what do you think?

do i have to make sure the other side received the message? before update the local chat?

and if the other side didn't receive the message just send it again?




Duke

@Joseman
If the other end did not receive the message (even if send was succesful). You could add your own handshake.

Ie one side send a message "hello other guy", now make a counter a long with the message ie. 01,00,"hello other guy".
In the other end if it receives the message, it would reply 01,00,"OK" or something, so you check for confirmation on the side that is sending, that it's actually received.
Have a timeout and if it doesn't get a response, re-send the message.

Of course always check for disconnection on the status and go through the entire re-connection process if so.

Powered by SMFPacks Menu Editor Mod