7 Replies - 1165 Views - Last Post: 25 June 2013 - 07:44 AM Rate Topic: -----

#1 Shazer2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-December 11

Small socket work

Posted 25 December 2011 - 03:51 PM

I am trying to set up a client/server relationship, so I can eventually send a message to the server, and then each client will receive the message sent. I currently have the following code:

Server.cs
/*
 * Created by SharpDevelop.
 * User: Shannon
 * Date: 12/26/2011
 * Time: 9:32 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Net;
using System.Net.Sockets;

namespace Server
{
	class Program
	{
		public static void Main(string[] args)
		{
			IPAddress ip = IPAddress.Parse("127.0.0.1");
			int port = 2222;
			byte[] buffer = new byte[256];
			
			IPEndPoint IPe = new IPEndPoint(ip, port);
			
			Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
			sock.Bind(IPe);
			sock.Listen(0);
			sock.Accept();
			sock.Receive(buffer, 256, SocketFlags.None);
			sock.Send(buffer, 256, SocketFlags.None);
			sock.Close();
		}
	}
}



Client.cs
/*
 * Created by SharpDevelop.
 * User: Shannon
 * Date: 12/26/2011
 * Time: 9:01 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Net.Sockets;
using System.Net;

namespace Client
{
	class Program
	{
		public static void Main(string[] args)
		{	
			IPAddress ip = IPAddress.Parse("127.0.0.1");
			int port = 2222;
			byte[] buffer = new byte[256];
			
			EndPoint ep = new IPEndPoint(ip, port);
			
			Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
			sock.Connect(ep);
			
			byte[] msg = Console.ReadLine(); // Can't convert from byte[] to string, not sure what to do.
			
			sock.Send(msg, 256, SocketFlags.None);
			sock.Receive(buffer, 256, SocketFlags.None);
			
			
			sock.Close();
		}
	}
}



I'm just having trouble with the input. I've tried to search up client/server examples, but nobody seems to be doing anything similar.

Is This A Good Question/Topic? 0
  • +

Replies To: Small socket work

#2 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: Small socket work

Posted 26 December 2011 - 04:48 AM

Take a look at a tutorial here:

Basic Client/Server Chat Application in C#

And I'm not sure how you concluded that there are no examples of what you're looking for.

There's a TON of information on Google

Introduction to TCP client server in C#
Simple Client-server Interactions using C#
C# Tutorial - Simple Threaded TCP Server
Asynchronous Socket Programming in C#: Part I
C# Client Socket program
A Chat Client/Server Program for C#

And remember we're not your google-bots, before asking questions please do a proper search yourself.

Take a look at these tutorials on how to do a proper search:

The Basic Guide to MSDN
Getting what you need by doing a decent search of the internet

This post has been edited by RexGrammer: 26 December 2011 - 05:03 AM

Was This Post Helpful? 2
  • +
  • -

#3 alaafz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-June 13

Re: Small socket work

Posted 20 June 2013 - 02:57 AM

I am searching for GUI Based tutorial. What is term is to used to make Voice call in C# Socket.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3162
  • View blog
  • Posts: 9,547
  • Joined: 05-May 12

Re: Small socket work

Posted 20 June 2013 - 05:26 AM

All the concepts that you learn doing a console based chat will apply equally well to a GUI. Do you mean to say that you want ready made code that you can copy?

As for "Voice call in C# Socket", look for "Voice over IP".
Was This Post Helpful? 1
  • +
  • -

#5 alaafz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-June 13

Re: Small socket work

Posted 22 June 2013 - 07:27 AM

Thanks for reply. Yes Actually i need tutorial voice chat via C# Socket.
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3162
  • View blog
  • Posts: 9,547
  • Joined: 05-May 12

Re: Small socket work

Posted 22 June 2013 - 11:22 AM

Try searching for "peer to peer voice chat" I'm quite sure that Google will not let you down.
Was This Post Helpful? 0
  • +
  • -

#7 alaafz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-June 13

Re: Small socket work

Posted 25 June 2013 - 07:38 AM

I have found the topic related C#P2P VOICE/VIDEO application
Video Chat Application Samples
But it's fully completed guide isn't provided. can anyone help me to fulfill when error comes.
Was This Post Helpful? 0
  • +
  • -

#8 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4309
  • View blog
  • Posts: 7,463
  • Joined: 08-June 10

Re: Small socket work

Posted 25 June 2013 - 07:44 AM

Try following it and see what happens. We won't do it for you, but if you have specific errors, we'll help you troubleshoot them. Our purpose here is to help you be a better programmer.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1