Find Jobs
Hire Freelancers

Simple multiuser chat server in java (basic stuff)

$30-5000 USD

กำลังดำเนินการ
โพสต์ มากกว่า 13 ปีที่ผ่านมา

$30-5000 USD

ชำระเงินเมื่อส่งงาน
The purpose of the project is to run a multithreaded socket server written in java and which is essentially some kind of chat server. The key words here are "multithreaded" and "chatserver" so every connected client has of course its own socket connection in its own thread. I made something like that myself, but the problem is that the system accepts connections nicely and gives every user its own thread, but threads are not released anymore, so my program eats memory in the long run. I am a fairly good programmer in a lot of languages, but I do need the core of the chatserver written in efficient code so I'm sure it handles connections (and most importantly DISconnections) correctly and solid. ## Deliverables Ok, so here comes the description of what I need. I want to make little educational flash games and they will be multiplayer. For the backend (the multiplayer handling) I want to use a **java program socket server**. The program must accept connections **(sockets) on port 2222** and I want for example **maximum of 200 connected** users. The server must be multithreaded, giving every client who connects its own thread. The server program must contain the following global variables 1: int ActiveConnections (contains how many clients are connected) 2: Socket[] sockets (contains a reference to the connected clients. Since there are max 200 users, this array will be max 200 items big) 3: String[] nicknames (contains the nickname of a a connected user. So if a client is connected on the socket sockets[5], then his nickname will be saved in nicknames[5]. This makes it easy to add functionality to the server) 4: String[] rooms (contains the name of a chatroom where a user joins to. So if a user is connected and his socket is sockets[5], then his nickname is saved in nicknames[5] and the room he is in is also saved in rooms[5] ...I can easily add global variabeles later to add functionality on startup of the program ActiveConnections will be 0, the Sockets array will contain 200 times the null and the string arrays nicknames and rooms will contain empty strings So, if a user **CONNECTS** to port 2222 (in the beginning we test by telnet) then the server must **accept the connection and create a thread for it**. In the same time the server must make sure the global var ActiveConnections reflects the correct number of connections + on connect the server looks into the array sockets[] to see what is the first empty slot in that array. In that first slot it will then save a reference to the socket of that connected client. That way later on in the server we can easily lookup a connected user by looping over the 200 array elements and see what socket matches. If we find a matching socket, then we also have found the index to set/get the nickname of set/get the room of this user. So its very easy to work with If a user **DISCONNECTS** (for any reason, even timing out connections and whatever), then the server **should detect** this. The ActiveConnections counter should be adjusted and the **thread should be released**. Of course it would also require to lookup the socket in the sockets[] array, set it to null and also set the nicknames[] and rooms[] corresponding with this socket to an empty string. So, if 100 customers connect to the server and they all close the connection over time, then no ghost threads may remain active. The sockets and threads should **100% surely be released again** to save on resources on the server. So far I explained the server "connect" and "disconnect", now there is still a little bit to say about basic communication Clients who are logged in can send messages (which are strings which I think are ended by CRLF) and of course the server can also send data back to clients. So what are the basic functions needed (the rest I'll make myself) 1) If a client sends a message in the format "NICK:mynickname" then the server should detect that the message began with "NICK:", lookup the index of the active socket in the sockets[] array and thereby find the index in this array. If for example the server found a reference to the socket in sockets[4], then the nickname received (the message minus the first 5 characters "NICK:" should be saved in nicknames[4] 2) If a client sends a message in the format "JOIN:roomname" then the server should detect that the message began with "JOIN:", lookup the index of the active socket in the sockets[] array and thereby find the index in this array. If for example the server found a reference to the socket in sockets[4], then the roomname received (the message minus the first 5 characters "JOIN:" should be saved in rooms[4] I can later add anything I want based on this basic framework, because whenever you receive something on the server side, it looks up the index into the array of sockets and I can get very easy to the various items like nickname, room, .... because all I needed was the index into the array. Now the communication part from the server to clients. because all clients are nicely stored into the array sockets[], nicknames[],rooms[] , it is quite easy to create the following functions which should send back a string to the client 1) **sendPrivateMessage(String nickname,String message)** (you can easily find the socket to send to by iterating the nicknames[] array, stopping when the correct nickname is found and then based on the found index you can find the socket in the sockets[] array. 2) **sendRoomMessage(String roomname,String message)** (you can easily find the socket to send to by iterating the rooms[] array, and everytime when the correct room is found you can find the socket in the sockets[] array (its the same index) and send that client the message. of course if multiple clients are in that room, then they will all get that message, but you just iterate over the rooms[] array (only 200 items max) and send a msg if needed. I think that is about it. I'm quite confident that this can be coded in 100-200 lines of java code. to be honest I was able to write a big part of it allread myself, but the problem always comes when the client closes connection. With all tries I made the threads never were given back to the system and after some time it began to eat resources. So this is a very important part of the job. to make sure that connecting,disconnecting is very solid. No exceptions on disconnects. I think that a good java programmer should not have a lot of work with creating this. Its very basic stuff but the keyword is probably threads here. If anything would not be clear in my explanation, then please ask.
รหัสโปรเจกต์: 3782348

เกี่ยวกับโปรเจกต์

6 ข้อเสนอ
โปรเจกต์ระยะไกล
ใช้งานอยู่ 14 ปีที่ผ่านมา

กำลังมองหาการสร้างรายได้ใช่ไหม?

ประโยชน์ของการประมูลกับ Freelancer

กำหนดงบประมาณและกรอบเวลาของคุณ
รับเงินจากการงานของคุณ
อธิบายข้อเสนอของคุณในภาพรวม
ลงทะเบียนและเสนอราคาฟรี
หมอบหมายให้:
รูปอวาตาร์ของผู้ใช้
See private message.
$97.75 USD ใน 14 วัน
4.9 (50 รีวิว)
6.0
6.0
6 ฟรีแลนซ์กำลังเสนอราคาโดยเฉลี่ย $96 USD สำหรับงานนี้
รูปอวาตาร์ของผู้ใช้
See private message.
$127.50 USD ใน 14 วัน
5.0 (229 รีวิว)
6.9
6.9
รูปอวาตาร์ของผู้ใช้
See private message.
$178.50 USD ใน 14 วัน
5.0 (38 รีวิว)
5.7
5.7
รูปอวาตาร์ของผู้ใช้
See private message.
$59.50 USD ใน 14 วัน
5.0 (35 รีวิว)
5.3
5.3
รูปอวาตาร์ของผู้ใช้
See private message.
$85 USD ใน 14 วัน
3.7 (5 รีวิว)
2.6
2.6
รูปอวาตาร์ของผู้ใช้
See private message.
$25.50 USD ใน 14 วัน
0.0 (0 รีวิว)
0.0
0.0

เกี่ยวกับลูกค้า

ปักธงของ BELGIUM
Wervik, Belgium
5.0
2
ยืนยันวิธีการชำระเงินแล้ว
เป็นสมาชิกตั้งแต่ พ.ย. 8, 2007

การยืนยันลูกค้า

ขอบคุณ! เราได้ส่งลิงก์สำหรับเครดิตฟรีให้คุณทางอีเมลแล้ว
เกิดข้อผิดพลาดขณะส่งอีเมลของคุณ กรุณาลองอีกครั้ง
โลโก้ Freelancer Thailand / ภาษาไทย ช่วยเหลือและสนับสนุน FreelancerประเภทโปรเจคการประกวดFreelancerองค์กรแพ็กเกจสมาชิกโครงการ Freelancer ชั้นแนวหน้าการจัดการโปรเจคงานในพื้นที่Photo Anywhereหน้าจัดแสดงผลงานAPI สำหรับนักพัฒนาได้รับการยืนยันDesktop App เกี่ยวกับเกี่ยวกับเราวิธีใช้งานความปลอดภัยนักลงทุนแผนผังเว็บไซต์เรื่องราวข่าวออกสื่อทีมรางวัลข่าวประชาสัมพันธ์ร่วมงานกับเรา ข้อกำหนดนโยบายความเป็นส่วนตัวข้อกำหนดและเงื่อนไขนโยบายลิขสิทธิ์ข้อพึงปฏิบัติค่าธรรมเนียมและค่าบริการหุ้นส่วนEscrow.comLoadshiftWarrior Forum แอปโลโก้ Apple App Store โลโก้ Google Play
ไม่สามารถคัดลอกไปยังคลิปบอร์ดได้ โปรดลองอีกครั้งหลังปรับเปลี่ยนการอนุญาต
คัดลอกไปยังคลิปบอร์ดแล้ว
ผู้ใช้ที่ลงทะเบียน งานที่มีการโพสต์ทั้งหมด
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
กำลังโหลดตัวอย่าง
ได้รับอนุญาตสำหรับตำแหน่งทางภูมิศาสตร์
เซสชั่นการเข้าสู่ระบบของคุณหมดอายุและคุณได้ออกจากระบบแล้ว กรุณาเข้าสู่ระบบอีกครั้ง