Yep, here's a little chat client I did.
Bear in mind I wrote this over a year ago I think..so if anyone has questions..don't be vague..be explicit. ;)
Type player
Field x,y,z
Field netId
End Type
initMultiSys()
d$ =Input("1 = server,2=client>")
If d=1
test.server =createServer( "test")
If test=Null End
Print "server created, I.P>"+serverIP( test)
Else If d=2
cli.client =connectClient(Input("127.0.0.0 = local>"))
If cli =Null End
Print " connected to server"
EndIf
;Graphics 320,240,0,2
;SetBuffer BackBuffer()
Repeat
If d=1 ;server
eventCount =srvEventCount( test)
If eventCount
For j=1 To eventCount
Select srvGetEvent( test,j)
Case sNewClient ;sNewClient = lib const. New clinet has logged on.
player.player = New player ;player type is specific to the this example only.
player\netId =srvGetEventNetId( test,j) ;get the net id of the client just logged on.
Print "new client joined."
Case gNewData ;data has been recieved.
For player.player =Each player ;\let's find the player that has the same net id
If player\netId = srvGetEventNetId( test,j) ;as the sender of the data./
Select srvGetEventChannel( test,j) ;get the channel id string
Case "chat" ;see clSendString for where 'chat' originates from
msg$ =srvGetEventString( test,j) ;get the string.
Print ">"+msg
srvBroadCastString( test,msg,"chat") ;route to all other clients.
End Select
EndIf
Next
End Select
Next
EndIf
If KeyDown(57) srvBroadCastString(test,0,Input(">"),"chat")
;srvSendString( server, netIdtoSendTo,string) to send to just one client.
Else ;client
;clSendString( client, string to send, channel(Optional par) channel can be any text string.(Custom)
If KeyDown(57) clSendString( cli,Input(">"),"chat")
eventCount =clEventCount( cli) ;same syntax as server funs
If eventCount
For j=1 To eventCount
Select clGetEvent( cli,j)
Case gNewData
Select clGetEventChannel( cli,j)
Case "chat"
Print clGetEventString( cli,j)
End Select
End Select
Next
EndIf
EndIf
netCycle()
Until KeyDown(1)
|