Alright, here are the networking parts of my code. I took out the gadget and sound playing bits, as I don't think they would effect it at all.
Server
Code:
Global NewMap Users.S()
#MSG_WAITALL=$8
Declare Main()
Procedure Main()
OpenConsole("Talk Server.")
InitNetwork()
Protected Port=6832
Delay(50)
If CreateNetworkServer(0,Port)
PrintN("Server created (Port "+Str(Port)+").")
If ReadFile(0,"MOTD.txt")
Protected MOTD.S=ReadString(0)
EndIf
Repeat
Protected SEvent=NetworkServerEvent()
If SEvent
Protected ClientID=EventClient()
Select SEvent
Case #PB_NetworkEvent_Connect
ID=ClientID
PrintN(""+ID+" has connected !")
Case #PB_NetworkEvent_Data
*Buffer=AllocateMemory(1000)
recv_(ClientID,*Buffer,1000,#MSG_WAITALL)
ID=ClientID
Protected PeekedMem.S=""
PeekedMem=PeekS(*Buffer,-1,#PB_UTF8)
Debug PeekedMem
If Left(PeekedMem,1)="@"
Protected Name.S=Mid(PeekedMem,2)
Users(Str(ID))=Name
Protected MOTDString.S="@MOTD "+MOTD
send_(Val(MapKey(Users())),@MOTDString,StringByteLength(MOTDString),#Null)
recv_(ID,*Buffer,1000,#MSG_WAITALL)
Protected NameString.S=Name+" has connected"
ForEach Users()
send_(Val(MapKey(Users())),@NameString,StringByteLength(NameString),#Null)
Next
Else
If FindMapElement(Users(),Str(ID))
Protected Chat.S=Users()+": "+PeekedMem
PrintN(Chat)
ForEach Users()
send_(Val(MapKey(Users())),@Chat,StringByteLength(Chat),#Null)
Next
EndIf
EndIf
FreeMemory(*Buffer)
Case #PB_NetworkEvent_Disconnect
ID=ClientID
PrintN(""+ID+" has disconnected !")
EndSelect
EndIf
ForEver
CloseNetworkServer(0)
Else
PrintN("Can't create the server (port in use ?).")
EndIf
EndProcedure
Main()
And client
Code:
InitNetwork()
Protected Port=6832
Protected Name.S=InputRequester("Name","Please enter your name.","")
If Name=""
End
EndIf
Protected ConnectionID=OpenNetworkConnection("127.0.0.1",Port)
If ConnectionID
send_(ConnectionID,@Name,StringByteLength(Name),#Null)
Protected TempName.S="@"+Name
send_(ConnectionID, @TempName,StringByteLength(TempName),#Null)
Repeat
Protected SEvent=NetworkClientEvent(ConnectionID)
Select SEvent
Case #PB_NetworkEvent_Disconnect
ConnectionID=0
PlaySound(Disconnect)
Break
Case #PB_NetworkEvent_Data
If ConnectionID=0
Break
EndIf
Protected *Buffer=AllocateMemory(1000)
recv_(ConnectionID,*Buffer,1000,#MSG_WAITALL)
Protected Message.S=PeekS(*Buffer,-1,#PB_UTF8)
If FindString(Message,": ")=0
If FindString(Message,"has connected")<>0
PlaySound(Online)
ElseIf Left(Message,5)="@MOTD"
Message=Mid(Message,6)
EndIf
Else
PlaySound(Chat)
EndIf
AddGadgetItem(#History_List,-1,Message)
FreeMemory(*Buffer)
EndSelect
Protected Event=WaitWindowEvent(1)
Select Event
Case #PB_Event_Menu
Select EventMenu()
Case #Send
If GetActiveGadget()=#Chat_Field
Protected Content.S=GetGadgetText(#Chat_Field)
If Content=""
PlaySound(Empty)
Continue
Else
SendNetworkString(ConnectionID,Content,#PB_UTF8)
SetGadgetText(#Chat_Field,"")
PlaySound(Send)
EndIf
EndIf
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Exit_Button
CloseNetworkConnection(ConnectionID)
End
EndSelect
EndSelect
ForEver
EndIf
That is missing the gadget and sound loading/playing code, but you should be able to get the idea. The problem I was having was with mixing packets, and so I tried switching to send_() and recv_() from the WinAPI, but now nothing gets sent at all

.
// Edit: Code tags were added and the code indentation was corrected (Kiffi)