Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please give me an easy example on how can I connect these 2:

- TCP listener server working on localhost port 33333
and
- a Javascript client working on browser

I've searched JS sockets and all the links go to WebSockets or socket.io. They are very helpful if the server is created with the same framework.

Can you please help? :D

Edit:
Client side:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://cdn.socket.io/stable/socket.io.js"></script>

<script type="text/javascript">
// Create SocketIO instance, connect
var socket = new io.Socket('localhost',{
	port: 33333
});
socket.connect(); 

// Add a connect listener
socket.on('connect',function() {
	console.log('Client has connected to the server!');
});
// Add a connect listener
socket.on('message',function(data) {
	console.log('Received a message from the server!',data);
});
// Add a disconnect listener
socket.on('disconnect',function() {
	console.log('The client has disconnected!');
});

// Sends a message to the server via sockets
function sendMessageToServer(message) {
	socket.send(message);
}

</script>

<body> 

</body> 
</html>


This client code in JS doesn't even connect to the server.

Mention: the server works with a C# client.
Posted
Updated 6-Jan-12 6:02am
v4
Comments
R. Giskard Reventlov 6-Jan-12 11:53am    
What have you tried for yourself? Thisforum isfor answers to sepcific questions, not to get us to do your work for you.
Jamil Hallal 6-Jan-12 12:48pm    
are you trying to send an e-mail using javascript?
Lucian Adrian Rosu 6-Jan-12 14:00pm    
It's for a game. I'm trying to transfer an application to the browser.

Google for "TCP server C#" and you will find some easy samples that you can implement.
 
Share this answer
 
Comments
Lucian Adrian Rosu 6-Jan-12 12:32pm    
I do not want to change the programming languages. I need a javascript client to connect to my server.
Richard MacCutchan 6-Jan-12 12:54pm    
OK, try Googling for "Javascript TCP client".
Aydin Homay 13-Apr-16 19:04pm    
Give the answer if you know else leave it.
Richard MacCutchan 14-Apr-16 2:39am    
What answer?
Aydin Homay 16-Apr-16 15:50pm    
Instead of giving the right answer you are redirecting to the google !!!
Everybody knows how to search in google if you don`t know the answer don`t make it fuzzy
Google for "TCP server C#" Really !!!!? OhOhooOoh perfect
I think you are just not seeing the connect because you do the connect call before you have setup the listeners on your socket. So if you move the connect call after the listeners have been setup what happens then?

Alternately you could try to monitor the server program to observe any traces of client activity there.

Regards,

Manfred
 
Share this answer
 
All you need to know is here: http://code.google.com/p/bauglir-websocket/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900